Coder Social home page Coder Social logo

phpwebsocket's People

Watchers

James Cloos avatar

phpwebsocket's Issues

client and server not connecting - socket_connect() invalid resources......

What steps will reproduce the problem?
1. Start The Server
2. Start The Client
3. Server Keep Showing Socket_connect() invalid resources some path
   client shows WebSocket - status 0
    Disconnected - status 3

What is the expected output? What do you see instead?

program should work and user can chat happily


What version of the product are you using? On what operating system?

client.php------------------------------------------------------------

<html>
<head>
<title>WebSocket</title>

<style>
 html,body{font:normal 0.9em arial,helvetica;}
 #log {width:440px; height:200px; border:1px solid #7F9DB9; overflow:auto;}
 #msg {width:330px;}
</style>

<script>
var socket;

function init(){
  var host = "ws://localhost:12345/websocket/server.php";
  try{
    socket = new WebSocket(host);
    log('WebSocket - status '+socket.readyState);
    socket.onopen    = function(msg){ log("Welcome - status "+this.readyState); };
    socket.onmessage = function(msg){ log("Received: "+msg.data); };
    socket.onclose   = function(msg){ log("Disconnected - status "+this.readyState); };
  }
  catch(ex){ log(ex); }
  $("msg").focus();
}

function send(){
  var txt,msg;
  txt = $("msg");
  msg = txt.value;
  if(!msg){ alert("Message can not be empty"); return; }
  txt.value="";
  txt.focus();
  try{ socket.send(msg); log('Sent: '+msg); } catch(ex){ log(ex); }
}
function quit(){
  log("Goodbye!");
  socket.close();
  socket=null;
}

// Utilities
function $(id){ return document.getElementById(id); }
function log(msg){ $("log").innerHTML+="<br>"+msg; }
function onkey(event){ if(event.keyCode==13){ send(); } }
</script>

</head>
<body onload="init()">
 <h3>WebSocket v2.00</h3>
 <div id="log"></div>
 <input id="msg" type="textbox" onkeypress="onkey(event)"/>
 <button onclick="send()">Send</button>
 <button onclick="quit()">Quit</button>
 <div>Commands: hello, hi, name, age, date, time, thanks, bye</div>
</body>
</html>


server.php------------------------------------------------------------


<?php  /*  >php -q server.php  */

error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();

$master  = WebSocket("localhost",12345);
$sockets = array($master);
$users   = array();
$debug   = false;

while(true){
  $changed = $sockets;
  socket_select($changed,$write=NULL,$except=NULL,NULL);
  foreach($changed as $socket){
    if($socket==$master){
      $client=socket_accept($master);
      if($client<0){ console("socket_accept() failed"); continue; }
      else{ connect($client); }
    }
    else{
      $bytes = @socket_recv($socket,$buffer,2048,0);
      if($bytes==0){ disconnect($socket); }
      else{
        $user = getuserbysocket($socket);
        if(!$user->handshake){ dohandshake($user,$buffer); }
        else{ process($user,$buffer); }
      }
    }
  }
}

//---------------------------------------------------------------
function process($user,$msg){
  $action = unwrap($msg);
  say("< ".$action);
  switch($action){
    case "hello" : send($user->socket,"hello human");                       break;
    case "hi"    : send($user->socket,"zup human");                         break;
    case "name"  : send($user->socket,"my name is Multivac, silly I know"); break;
    case "age"   : send($user->socket,"I am older than time itself");       break;
    case "date"  : send($user->socket,"today is ".date("Y.m.d"));           break;
    case "time"  : send($user->socket,"server time is ".date("H:i:s"));     break;
    case "thanks": send($user->socket,"you're welcome");                    break;
    case "bye"   : send($user->socket,"bye");                               break;
    default      : send($user->socket,$action." not understood");           break;
  }
}

function send($client,$msg){
  say("> ".$msg);
  $msg = wrap($msg);
  socket_write($client,$msg,strlen($msg));
}

function WebSocket($address,$port){
  $master=socket_create(AF_INET, SOCK_STREAM, SOL_TCP)     or die("socket_create() failed");
  socket_set_option($master, SOL_SOCKET, SO_REUSEADDR, 1)  or die("socket_option() failed");
  socket_bind($master, $address, $port)                    or die("socket_bind() failed");
  socket_listen($master,20)                                or die("socket_listen() failed");
  echo "Server Started : ".date('Y-m-d H:i:s')."\n";
  echo "Master socket  : ".$master."\n";
  echo "Listening on   : ".$address." port ".$port."\n\n";
  return $master;
}

function connect($socket){
  global $sockets,$users;
  $user = new User();
  $user->id = uniqid();
  $user->socket = $socket;
  array_push($users,$user);
  array_push($sockets,$socket);
  console($socket." CONNECTED!");
}

function disconnect($socket){
  global $sockets,$users;
  $found=null;
  $n=count($users);
  for($i=0;$i<$n;$i++){
    if($users[$i]->socket==$socket){ $found=$i; break; }
  }
  if(!is_null($found)){ array_splice($users,$found,1); }
  $index = array_search($socket,$sockets);
  socket_close($socket);
  console($socket." DISCONNECTED!");
  if($index>=0){ array_splice($sockets,$index,1); }
}

function dohandshake($user,$buffer){
  console("\nRequesting handshake...");
  console($buffer);
  list($resource,$host,$origin,$strkey1,$strkey2,$data) = getheaders($buffer);
  console("Handshaking...");

  $pattern = '/[^\d]*/';
  $replacement = '';
  $numkey1 = preg_replace($pattern, $replacement, $strkey1);
  $numkey2 = preg_replace($pattern, $replacement, $strkey2);

  $pattern = '/[^ ]*/';
  $replacement = '';
  $spaces1 = strlen(preg_replace($pattern, $replacement, $strkey1));
  $spaces2 = strlen(preg_replace($pattern, $replacement, $strkey2));

  if ($spaces1 == 0 || $spaces2 == 0 || $numkey1 % $spaces1 != 0 || $numkey2 % $spaces2 != 0) {
        socket_close($user->socket);
        console('failed');
        return false;
  }

  $ctx = hash_init('md5');
  hash_update($ctx, pack("N", $numkey1/$spaces1));
  hash_update($ctx, pack("N", $numkey2/$spaces2));
  hash_update($ctx, $data);
  $hash_data = hash_final($ctx,true);

  $upgrade  = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" .
              "Upgrade: WebSocket\r\n" .
              "Connection: Upgrade\r\n" .
              "Sec-WebSocket-Origin: " . $origin . "\r\n" .
              "Sec-WebSocket-Location: ws://" . $host . $resource . "\r\n" .
              "\r\n" .
              $hash_data;

  socket_write($user->socket,$upgrade.chr(0),strlen($upgrade.chr(0)));
  $user->handshake=true;
  console($upgrade);
  console("Done handshaking...");
  return true;
}

function getheaders($req){
  $r=$h=$o=null;
  if(preg_match("/GET (.*) HTTP/"   ,$req,$match)){ $r=$match[1]; }
  if(preg_match("/Host: (.*)\r\n/"  ,$req,$match)){ $h=$match[1]; }
  if(preg_match("/Origin: (.*)\r\n/",$req,$match)){ $o=$match[1]; }
  if(preg_match("/Sec-WebSocket-Key2: (.*)\r\n/",$req,$match)){ $key2=$match[1]; }
  if(preg_match("/Sec-WebSocket-Key1: (.*)\r\n/",$req,$match)){ $key1=$match[1]; }
  if(preg_match("/\r\n(.*?)\$/",$req,$match)){ $data=$match[1]; }
  return array($r,$h,$o,$key1,$key2,$data);
}

function getuserbysocket($socket){
  global $users;
  $found=null;
  foreach($users as $user){
    if($user->socket==$socket){ $found=$user; break; }
  }
  return $found;
}

function     say($msg=""){ echo $msg."\n"; }
function    wrap($msg=""){ return chr(0).$msg.chr(255); }
function  unwrap($msg=""){ return substr($msg,1,strlen($msg)-2); }
function console($msg=""){ global $debug; if($debug){ echo $msg."\n"; } }

class User{
  var $id;
  var $socket;
  var $handshake;
}

?>

websocket.class.php---------------------------------------------------

<?php  

// Usage: $master=new WebSocket("localhost",12345);

class WebSocket{
  var $master;
  var $sockets = array();
  var $users   = array();
  var $debug   = false;

  function __construct($address,$port){
    error_reporting(E_ALL);
    set_time_limit(0);
    ob_implicit_flush();

    $this->master=socket_create(AF_INET, SOCK_STREAM, SOL_TCP)     or die("socket_create() failed");
    socket_set_option($this->master, SOL_SOCKET, SO_REUSEADDR, 1)  or die("socket_option() failed");
    socket_bind($this->master, $address, $port)                    or die("socket_bind() failed");
    socket_listen($this->master,20)                                or die("socket_listen() failed");
    $this->sockets[] = $this->master;
    $this->say("Server Started : ".date('Y-m-d H:i:s'));
    $this->say("Listening on   : ".$address." port ".$port);
    $this->say("Master socket  : ".$this->master."\n");

    while(true){
      $changed = $this->sockets;
      socket_select($changed,$write=NULL,$except=NULL,NULL);
      foreach($changed as $socket){
        if($socket==$this->master){
          $client=socket_accept($this->master);
          if($client<0){ $this->log("socket_accept() failed"); continue; }
          else{ $this->connect($client); }
        }
        else{
          $bytes = @socket_recv($socket,$buffer,2048,0);
          if($bytes==0){ $this->disconnect($socket); }
          else{
            $user = $this->getuserbysocket($socket);
            if(!$user->handshake){ $this->dohandshake($user,$buffer); }
            else{ $this->process($user,$this->unwrap($buffer)); }
          }
        }
      }
    }
  }

  function process($user,$msg){
    /* Extend and modify this method to suit your needs */
    /* Basic usage is to echo incoming messages back to client */
    $this->send($user->socket,$msg);
  }

  function send($client,$msg){ 
    $this->say("> ".$msg);
    $msg = $this->wrap($msg);
    socket_write($client,$msg,strlen($msg));
    $this->say("! ".strlen($msg));
  } 

  function connect($socket){
    $user = new User();
    $user->id = uniqid();
    $user->socket = $socket;
    array_push($this->users,$user);
    array_push($this->sockets,$socket);
    $this->log($socket." CONNECTED!");
    $this->log(date("d/n/Y ")."at ".date("H:i:s T"));
  }

  function disconnect($socket){
    $found=null;
    $n=count($this->users);
    for($i=0;$i<$n;$i++){
      if($this->users[$i]->socket==$socket){ $found=$i; break; }
    }
    if(!is_null($found)){ array_splice($this->users,$found,1); }
    $index=array_search($socket,$this->sockets);
    socket_close($socket);
    $this->log($socket." DISCONNECTED!");
    if($index>=0){ array_splice($this->sockets,$index,1); }
  }

  function dohandshake($user,$buffer){
    $this->log("\nRequesting handshake...");
    $this->log($buffer);
    list($resource,$host,$origin,$key1,$key2,$l8b) = $this->getheaders($buffer);
    $this->log("Handshaking...");
    //$port = explode(":",$host);
    //$port = $port[1];
    //$this->log($origin."\r\n".$host);
    $upgrade  = "HTTP/1.1 101 WebSocket Protocol Handshake\r\n" .
                "Upgrade: WebSocket\r\n" .
                "Connection: Upgrade\r\n" .
                                //"WebSocket-Origin: " . $origin . "\r\n" .
                                //"WebSocket-Location: ws://" . $host . $resource . "\r\n" .
                "Sec-WebSocket-Origin: " . $origin . "\r\n" .
                    "Sec-WebSocket-Location: ws://" . $host . $resource . "\r\n" .
                    //"Sec-WebSocket-Protocol: icbmgame\r\n" . //Client doesn't send this
                "\r\n" .
                    $this->calcKey($key1,$key2,$l8b) . "\r\n";// .
                        //"\r\n";
    socket_write($user->socket,$upgrade.chr(0),strlen($upgrade.chr(0)));
    $user->handshake=true;
    $this->log($upgrade);
    $this->log("Done handshaking...");
    return true;
  }

  function calcKey($key1,$key2,$l8b){
        //Get the numbers
        preg_match_all('/([\d]+)/', $key1, $key1_num);
        preg_match_all('/([\d]+)/', $key2, $key2_num);
        //Number crunching [/bad pun]
        $this->log("Key1: " . $key1_num = implode($key1_num[0]) );
        $this->log("Key2: " . $key2_num = implode($key2_num[0]) );
        //Count spaces
        preg_match_all('/([ ]+)/', $key1, $key1_spc);
        preg_match_all('/([ ]+)/', $key2, $key2_spc);
        //How many spaces did it find?
        $this->log("Key1 Spaces: " . $key1_spc = strlen(implode($key1_spc[0])) );
        $this->log("Key2 Spaces: " . $key2_spc = strlen(implode($key2_spc[0])) );
        if($key1_spc==0|$key2_spc==0){ $this->log("Invalid key");return; }
        //Some math
        $key1_sec = pack("N",$key1_num / $key1_spc); //Get the 32bit secret key, minus the other thing
        $key2_sec = pack("N",$key2_num / $key2_spc);
        //This needs checking, I'm not completely sure it should be a binary string
        return md5($key1_sec.$key2_sec.$l8b,1); //The result, I think
  }

  function getheaders($req){
    $r=$h=$o=null;
    if(preg_match("/GET (.*) HTTP/"               ,$req,$match)){ $r=$match[1]; }
    if(preg_match("/Host: (.*)\r\n/"              ,$req,$match)){ $h=$match[1]; }
    if(preg_match("/Origin: (.*)\r\n/"            ,$req,$match)){ $o=$match[1]; }
    if(preg_match("/Sec-WebSocket-Key1: (.*)\r\n/",$req,$match)){ $this->log("Sec Key1: ".$sk1=$match[1]); }
    if(preg_match("/Sec-WebSocket-Key2: (.*)\r\n/",$req,$match)){ $this->log("Sec Key2: ".$sk2=$match[1]); }
    if($match=substr($req,-8))                                                                  { $this->log("Last 8 bytes: ".$l8b=$match); }
    return array($r,$h,$o,$sk1,$sk2,$l8b);
  }

  function getuserbysocket($socket){
    $found=null;
    foreach($this->users as $user){
      if($user->socket==$socket){ $found=$user; break; }
    }
    return $found;
  }

  function     say($msg=""){ echo $msg."\n"; }
  function     log($msg=""){ if($this->debug){ echo $msg."\n"; } }
  function    wrap($msg=""){ return chr(0).$msg.chr(255); }
  function  unwrap($msg=""){ return substr($msg,1,strlen($msg)-2); }

}

class User{
  var $id;
  var $socket;
  var $handshake;
}

?>

Please provide any additional information below.


please help me with this i'm in lot  of stress becouse of this


Original issue reported on code.google.com by [email protected] on 30 Nov 2011 at 6:55

Messages longer than 127 characters not decoded.

When sending messages that are longer than a 127 characters messages are not 
decoded and appear like this when I debug the hp socket server by passing the 
message to say():
��<c��en��sg��ty��>M��sa��</��pe��au��or
��hr��</��th��><��>1��.0��.1��ip��ms��as
��gh��ms��<d��et��e>��fa��</��te��me��/c
��en��sg�
> 
��<c��en��sg��ty��>M��sa��</��pe��au��or
��hr��</��th��><��>1��.0��.1��ip��ms��as
��gh��ms��<d��et��e>��fa��</��te��me��/c
��en��sg�

If I make the message one character shorter it works fine. Any ideas?



Original issue reported on code.google.com by [email protected] on 29 Nov 2011 at 11:30

Rewrite of your code ...

Please provide any additional information below.

i have written a more "classified" version of your server, maybe u can use it 
for your project?

http://bohuco.net/dev/websocket/?source=WebSocketServer.php
http://bohuco.net/dev/websocket/?source=server.php


Original issue reported on code.google.com by [email protected] on 12 Jul 2010 at 2:44

Undefined variable sk2

WebServerSocket.php produce a notice about sk2 not defined. I will try to find 
more about this sk variable by checking with the protocol, but if someone has a 
clue, please give you thought.

Original issue reported on code.google.com by [email protected] on 22 Feb 2011 at 2:04

MIT License

The current license for phpwebsocket is the GNU GPL; aka a "viral" license. 
Could you switch the license to something a little more friendly, like the MIT 
license?
(I'm not a lawyer, but you might need sign off from all the committers as well.)

Original issue reported on code.google.com by [email protected] on 26 Feb 2011 at 6:38

How do I bind to external address?

What steps will reproduce the problem?
1. changing the localhost in line 8 to become some external ip (e.g. 
externalip.no-ip.org)
from ~~~~ $master  = WebSocket("localhost",22222);
to ~~~~~~ $master  = WebSocket("externalip.no-ip.org",22222);

What is the expected output? What do you see instead?
Expected output: 
Server Started : 2010-05-26 18:46:24
Master socket  : Resource id #4
Listening on   : externalip.no-ip.org port 22222

but I see:
Warning: socket_bind(): unable to bind address [49]: Can't assign requested 
address in 
../server.php on line 60
socket_bind() failed.


What version of the product are you using? On what operating system?
r6
osx snow leopard


Thanks a lot!

Original issue reported on code.google.com by [email protected] on 26 May 2010 at 6:50

Error during WebSocket handshake: 'Sec-WebSocket-Accept' header is missing

What steps will reproduce the problem?
1. Open Websocket with Chrome or Safari (latest)
2. Check Error Console

What is the expected output? What do you see instead?
the serverside isn't sending: Sec-WebSocket-Accept

What version of the product are you using? On what operating system?
latest, Centos 64x

Please provide any additional information below.
see: http://dcspensley.com/pixelboard/

Original issue reported on code.google.com by [email protected] on 19 Sep 2011 at 8:26

Failure using the webSocket functionality in Firefox 4 Beta 1

What steps will reproduce the problem?
1. Use client Firefox 4 Beta 1(Has socket support)
2. Handshake never completes, shows WebSocket - status 0
3. Opening client page in Chrome works ok. 

What is the expected output? What do you see instead?

A command yields "[Exception... "An attempt was made to use an object that is 
not, or is no longer, usable" code: "11" nsresult: "0x8053000b 
(NS_ERROR_DOM_INVALID_STATE_ERR)" location: 
"file:///C:/Users/Bt/Desktop/sock.html Line: 34"] 


What version of the product are you using? On what operating system?
Windows 7, Firefox 4 Beta 1

Please provide any additional information below.

Works on chrome. A little googling, is this related to Handhake Protocol 75 and 
76 and line terminators? As described here: 
http://webreflection.blogspot.com/2010/06/websocket-handshake-76-simplified.html


Original issue reported on code.google.com by [email protected] on 11 Jul 2010 at 12:28

Update of WebSocket protocol - draft76

What steps will reproduce the problem?
That code doesn't work with recent versions of browser (Firefox 4 beta 6,...)

What is the expected output? What do you see instead?
The client is immediatly disconnetes

What version of the product are you using? On what operating system?
Firefox 4 beta 6

Please provide any additional information below.
This is because of an update of the WebSocket protocol draft76) and a new 
implementation in latest versions of browser : 
http://blog.chromium.org/2010/06/websocket-protocol-updated.html.

I attach a new version of the server that works (without backward 
compatibility).

Original issue reported on code.google.com by [email protected] on 24 Nov 2010 at 11:17

Attachments:

PHP Warning: socket_select(): 9 is not a valid Socket resource

What steps will reproduce the problem?
1. sudo php -q server.php
2. 192.168.1.15/client.html
3. refresh chrome explorer some times

What is the expected output? What do you see instead?
Stay connected to the chat.
Some times it disconnects from the chat, and on the server side it shows 
messages
PHP Warning:  socket_select(): 6 is not a valid Socket resource in 
/var/www/websocket/server.php on line 15
PHP Warning:  socket_select(): 7 is not a valid Socket resource in 
/var/www/websocket/server.php on line 15
PHP Warning:  socket_select(): 8 is not a valid Socket resource in 
/var/www/websocket/server.php on line 15
PHP Warning:  socket_select(): 11 is not a valid Socket resource in 
/var/www/websocket/server.php on line 15


What version of the product are you using? On what operating system?
Downloadad client.php and server.php from project home 13th June
Server side Ubuntu 11 + Apache2 + PHP5
Client side Windows XP SP3 + Chrome 12

Please provide any additional information below.
I haven't checked the code yet, as it's my first time working with sockets.

Original issue reported on code.google.com by [email protected] on 15 Jun 2011 at 10:37

Obsolete -- doesn't support latest standard (hybi-10)

In December 2011, I downloaded this code and it didn't work -- failed 
handshake.  On investigation, I found that the server code is based on a 
now-obsolete standard (not supported by Google Chrome browser).

On further searching, I found https://github.com/esromneb/phpwebsocket which is 
almost identical to this project except that it does support the latest 
WebSocket standard (called hybi-10).  I had no  problem with this code, worked 
the first time with Chrome.

So ... do we update this Google Code project to match the one in github?  Do we 
cancel this project to avoid misleading poor schlubs like me?  I'm not familiar 
with how we keep things honest here.

--Dave
[email protected]

Original issue reported on code.google.com by [email protected] on 18 Dec 2011 at 10:20

error "not a valid Socket resource"

What steps will reproduce the problem?
1. start the server
2. load the file client.html in Google Chrome
3.

What is the expected output? What do you see instead?
The server is expected to work, but it's showing the following error instead:
Warning: socket_select(): 5 is not a valid Socket resource in 
/home/mink500/public_html/test/server.php on line 15

What version of the product are you using? On what operating system?
r8

Please provide any additional information below.
I tried to make the server work locally using XAMPP (Apache and PHP) but I got 
the same error. I also tried to change ports and follow the instructions in 
this issue:
http://code.google.com/p/phpwebsocket/issues/detail?id=33
But I still get the error "5 is not a valid Socket resource" and the 
application is disconnected. 
I remember that refreshing the page several times I got it running a few months 
ago, but now it's impossible. Besides, it has to work all the time, not just 
after refreshing the page like 20 times.

Original issue reported on code.google.com by [email protected] on 31 Aug 2011 at 3:50

Software not updated to RFC6455

Hello,
am I wrong of the implemented websocket protocol is not the one from RFC6455?

I have started updating this software to the protocol described in RFC6455, but 
I'd like to share it with others to improve and test it.

Drop me a line at [email protected] if interested

Leandro

Original issue reported on code.google.com by [email protected] on 31 Mar 2012 at 3:35

First message ignored due to unnecessary ELSE

Before the process is called, the system attempts to see if the user has been 
"handshaked" and, if not, commits the handshake and stores the user.

For some reason, with my Chrome testing, the else block after this conditional 
statement is causing the first message sent to be ignored. I have corrected 
this by removing the else.

See attached file with comments. (Lines 38-40)

Original issue reported on code.google.com by [email protected] on 25 Apr 2011 at 12:24

Attachments:

code setup problem

What steps will reproduce the problem?
1. I follow your instruction and setup the file ( client.html and 
server.php ) and start the server. 

What is the expected output? What do you see instead?
When I go to the client in my chrome, I saw

WebSocket - status 0
in text box

and when I send message from client.html, I have this

Error: INVALID_STATE_ERR: DOM Exception 11


What version of the product are you using? On what operating system?
I'm using this one Ubuntu 10.04 Chrome


Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 25 May 2010 at 5:38

Wrong HandShake final byte

Please provide any additional information below.

In the dohandshake function, you write on the socket $upgrade.chr(0) . Your 
0x00 byte hasn't to be there. When you add the msg received to DOM, it's all ok 
but if you print it with an alert, it won't print as there is still a 0x00 byte 
at the beginning of the msg.

Original issue reported on code.google.com by [email protected] on 3 Aug 2010 at 6:38

Connects, but immediately disconnects

What steps will reproduce the problem?

Run the demo as documented:
1. Run 'php -q server.php' on the back end
2. Load 'client.html' into the front end. 

What is the expected output? What do you see instead?

Expecting the Demo to run

Instead, when I run 'client.html', I get the following:

WebSocket - status 0
Disconnected - status 3

What version of the product are you using? On what operating system?

- 5.3.5-1ubuntu7.2 (Ubuntu Natty)
- Chrome 13.0.782.215 (Windows 7 x64)

Please provide any additional information below.

I get the Disconnected - status 3 message about a second or two after the 
initial status 0 message.

Original issue reported on code.google.com by [email protected] on 26 Aug 2011 at 2:11

the client.php can't connect the server successfully for every time

What steps will reproduce the problem?
1. refresh the client.php


What version of the product are you using? On what operating system?
WinXP SP3, chrome 9.0.597.19 dev

Please provide any additional information below.
I downloaded the client.php and server.php.I follow the steps to run the 
demo.But,when I refresh the client.php, it can't connect the server 
successfully every time.Does anyone have the same problem?

Original issue reported on code.google.com by [email protected] on 17 Dec 2010 at 11:46

onmessage being called multiple times

For long strings, the onmessage handler is called multiple times which is 
causing problems.  I tried to increase the buffer size in the websocket class:

$bytes = @socket_recv($socket,$buffer,50000,0);

That didn't help.

Any ideas?

Original issue reported on code.google.com by [email protected] on 2 May 2011 at 4:58

Unable to connect to server.php

What steps will reproduce the problem?
1. Copied server.php and client.html
2. Started server
3. Accessed client.html

What is the expected output? What do you see instead?
WebSocket - status 0
Disconnected - status 3

What version of the product are you using? On what operating system?
Latest in SVN.

Server: Linux 2.6.32-5-xen-686, Debian, PHP 5.3.3-7+squeeze3 with Suhosin-Patch

Client: Google Chrome: 15.0.874.120 m


Please provide any additional information below.
Please note: this is on an Amazon EC2 instance. It binds to the internal IP 
address of the instance.

Server Startup:

Server Started : 2011-11-15 17:51:59
Master socket  : Resource id #4
Listening on   : 10.161.46.7 port 12345


When client connects...:
Resource id #5 CONNECTED!

Requesting handshake...
GET /phpMonitor/phpwebsocket/server.php HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: <removed>:12345
Sec-WebSocket-Origin: http://drupal-api-external.myidrupal.com
Sec-WebSocket-Key: eXMxn8VG+e8ggX8wn/dyMg==
Sec-WebSocket-Version: 8
Cookie: __utma=36081407.1633026250.1320850778.1320850778.1321373913.2; 
__utmc=36081407; 
__utmz=36081407.1320850778.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)


Handshaking...
failed




Original issue reported on code.google.com by [email protected] on 15 Nov 2011 at 6:02

Unexpected T_STRING At Line 109

When you try to execute the server script(php -q server.php) you get this error 
message:

Parse error: syntax error, unexpected T_STRING in 
/Applications/XAMPP/xamppfiles/htdocs/socket/server.php on line 109


Original issue reported on code.google.com by [email protected] on 23 Jan 2011 at 3:16

focus

Almost nothing but frustrating thing...
In client.html in the send(); function, when the message is empty, the alert 
box come but when i clic 'OK', the focus isn't on the text box anymore.

if(!msg){ alert("Message can not be empty"); return; }
to
if(!msg){ alert("Message can not be empty"); txt.focus(); return; }
line 31

Original issue reported on code.google.com by [email protected] on 28 Oct 2010 at 1:57

PHP client for a WebSocket server

Is there a PHP client available for the server?

It already works great from the browser, but I have a scenario where it makes 
more sense to write to an already open WebSocet (started by phpwebsocket) from 
server-side PHP code instead of from the browser.

Thank you,

Original issue reported on code.google.com by [email protected] on 19 Apr 2011 at 11:44

Patch for /trunk/ phpwebsocket/server.php

updated the websocket program to use the current websocket specification used 
by firefox and chrome. should be compliant up to version 
17(http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17) 

likely still needs some work

Original issue reported on code.google.com by [email protected] on 6 Feb 2012 at 6:43

Attachments:

multiple client

What steps will reproduce the problem?
1. At same time, more than 1 client is not possible to send message. 

2.

3.

What is the expected output? What do you see instead?
Any number of clients should be able to send and receive message.


What version of the product are you using? On what operating system?
2.0

Please provide any additional information below.
None

Original issue reported on code.google.com by [email protected] on 13 Mar 2010 at 1:26

Recieved: Not understood

When I write something in the client, the server responds but also adds not
understood in the end, you know why?

Sent: hello
Received: hello not understood

Original issue reported on code.google.com by [email protected] on 29 Apr 2010 at 10:49

Having a message sent when client connect?

What steps will reproduce the problem?
1. Change the WebSocket.Class.php code to have :

$client=socket_accept($this->master);
          if($client<0){ $this->log("socket_accept() failed"); continue; }
          else{ $this->connect($client); 
          $this->send($client,"Default message");


What is the expected output? What do you see instead?
Instead of having the "Default message" nothing is sent and all broke.

Any idea?


Original issue reported on code.google.com by [email protected] on 22 Feb 2011 at 2:03

No multiple connections (Windows?)

What steps will reproduce the problem?
1. Open tab to use client
2. Open 2nd tab to use client at the same time

What is the expected output? What do you see instead?
A message about a connection. Disconneted

What version of the product are you using? On what operating system?


Please provide any additional information below.
I've been trying to get multiple connections to work for a while now and
have found one chunk of code that actually works for me under XP:
http://www.php.net/manual/en/function.socket-select.php#56241

Original issue reported on code.google.com by [email protected] on 25 Dec 2009 at 6:20

Post message from a standalone php file

I have the following php file:

<?php
    $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    socket_connect($sock, '127.0.0.1', 12345);

    $msg = 'hi';
    $len = strlen($msg);

    socket_sendto($sock, $msg, $len, 0, '127.0.0.1', 12345);
    socket_close($sock);
?>

I set the up and it works, but I want to send a message from the above PHP file 
to the server, can this be done? When I do, I get the following error: 

PHP Warning:  socket_select(): 5 is not a valid Socket resource in 
/Desktop/phpwebsocket-read-only/server.php on line 18

Can somebody help? Thanks

Original issue reported on code.google.com by [email protected] on 1 Sep 2011 at 1:14

Firefox 4 beta 6

What steps will reproduce the problem?
1. I have Firefox 4, beta 6
2. I am loading the client.php
3. server.php is working
------
Server Started : 2010-09-17 15:11:23
Master socket  : Resource id #4
Listening on   : 127.0.0.1 port 99910

-------

What is the expected output? What do you see instead?
WebSocket - status 0
Disconnected - status 3

What version of the product are you using? On what operating system?
Fedora Gnu/Linux

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 17 Sep 2010 at 12:17

Websocket Keys Use Outdated Protocol Draft

What steps will reproduce the problem?
1. Run the demo chat using a new version of Chrome/Chromium

What is the expected output? What do you see instead?
Client connects. User can chat happily.

Instead, handshake fails, client disconnects.

Please provide any additional information below.
The draft spec used to use 2 keys to authenticate the handshake, and the new 
spec uses only 1 key. This causes the handshake to always fail. See:
http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-09

Original issue reported on code.google.com by [email protected] on 15 Aug 2011 at 4:49

Client Will Not Connect

First, I really appreciate the time the makers of this have taken to put it 
together.

There's an issue.  I downloaded client.html, websocket.class.php, and 
server.php.  I changed the url in client.html, started server.php, and opened 
client.html on my localhost.  It only shows the message "WebSocket - status 0" 
message, but not the connected message.  When I send a message, it produces the 
error "Error: INVALID_STATE_ERR: DOM Exception 11", because it's trying to send 
a message and it's not connected.

I've spent a good hour and a half debugging, and decided to see if anyone else 
had figured out how to fix this.

One more note: when I end the server.php process with the client.html page up, 
it pops up the disconnected message.  ?

What steps will reproduce the problem?
1. Run demo
2. Send message

What is the expected output? What do you see instead?
Response from the socket, but instead an error.

What version of the product are you using? On what operating system?
Chromium 8.0.552.200 (65749) Ubuntu 10.10

Original issue reported on code.google.com by jonahbron.d on 18 Nov 2010 at 7:42

Websocket not connecting Error: INVALID_STATE_ERR: DOM Exception 11

What steps will reproduce the problem?
Follow the steps/instructions


What is the expected output? What do you see instead?
The client.html: WebSocket - status 0, for any command sent from client then - 
Error: INVALID_STATE_ERR: DOM Exception 11


What version of the product are you using? On what operating system?
phpwebsocket - as of 04/11/11, chrome - 10.0.648, php 5.3.5, Win-XP


Please provide any additional information below.
did check the prev issues reported on the same, but nothing useful found. I am 
not sure if this is a handshake problem. 
when I terminate server.php on the terminal, the Client.html prints: 
Disconnected - status 2 

Original issue reported on code.google.com by [email protected] on 11 Apr 2011 at 8:52

API-Documentation

If someone are interested in the API-Documentation of this files, you found it 
in my Attachment as HTML-Struktured Page.

Feel Free to add it to the wiki-page.

Original issue reported on code.google.com by [email protected] on 16 Sep 2010 at 4:11

Attachments:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.