Reputation: 10288
I've recently downloaded http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/
php classes to create a PHP web sockets server.
I've ran the startDaemon through command line and when I visit the client.php page, The handshake is clearly logged:
C:\wamp\bin\php\php5.3.5>php -f C:/wamp/www/socket/server/startDaemon.php
2011-09-09 13:55:42 System: Socket Resource id #7 created.
2011-09-09 13:55:42 System: Socket bound to localhost:8080.
2011-09-09 13:55:42 System: Start listening on Socket.
2011-09-09 13:56:40 WebSocket: Resource id #8 CONNECTED!
2011-09-09 13:56:40 WebSocket: Requesting handshake...
2011-09-09 13:56:40 WebSocket: Handshaking...
2011-09-09 13:56:40 WebSocket: Done handshaking...
2011-09-09 13:58:18 WebSocket: Resource id #8 disconnected!
2011-09-09 13:58:23 WebSocket: Resource id #9 CONNECTED!
2011-09-09 13:58:23 WebSocket: Requesting handshake...
2011-09-09 13:58:23 WebSocket: Handshaking...
2011-09-09 13:58:23 WebSocket: Done handshaking...
2011-09-09 13:59:14 WebSocket: Resource id #9 disconnected!
2011-09-09 13:59:14 WebSocket: Resource id #10 CONNECTED!
2011-09-09 13:59:14 WebSocket: Requesting handshake...
2011-09-09 13:59:14 WebSocket: Handshaking...
2011-09-09 13:59:14 WebSocket: Done handshaking...
2011-09-09 14:00:16 WebSocket: Resource id #11 CONNECTED!
2011-09-09 14:00:16 WebSocket: Requesting handshake...
2011-09-09 14:00:16 WebSocket: Handshaking...
2011-09-09 14:00:16 WebSocket: Done handshaking...
2011-09-09 14:00:16 WebSocket: Resource id #11 disconnected!
2011-09-09 14:00:23 WebSocket: Resource id #12 CONNECTED!
2011-09-09 14:00:23 WebSocket: Requesting handshake...
2011-09-09 14:00:23 WebSocket: Handshaking...
2011-09-09 14:00:23 WebSocket: Done handshaking...
2011-09-09 14:00:23 WebSocket: Resource id #12 disconnected!
2011-09-09 14:00:33 WebSocket: Resource id #13 CONNECTED!
2011-09-09 14:00:33 WebSocket: Requesting handshake...
2011-09-09 14:00:33 WebSocket: Handshaking...
2011-09-09 14:00:33 WebSocket: Done handshaking...
2011-09-09 14:00:33 WebSocket: Resource id #13 disconnected!
(me making a few connections to test)
my problem is I dont seem to be able to send or recieve info. in the php classes I have set stages to write 1,2,3... to the log at each point, which again you can clearly see through the command window. But when I try to send data, nothing is outputted to the log.
Si I then went to the front end and tried this
if(!("WebSocket" in window)){
$('#chatLog, input, button, #examples').fadeOut("fast");
$('<p>Oh no, you need a browser that supports WebSockets. How about <a href="http://www.google.com/chrome">Google Chrome</a>?</p>').appendTo('#container');
}else{
//The user has WebSockets
connect();
function connect(){
//var socket;
var host = "ws://localhost:8080/socket/server/startDaemon.php";
try{
var socket = new WebSocket(host);
socket.onopen = function(){
alert('open');
message('<p class="event">Socket Status: '+socket.readyState+' (open) </p>');
}
..........
........
WHere no alert is being made.... does anyone know what could be wrong here?
regards
Upvotes: 3
Views: 2059
Reputation: 4757
EDIT: It seems there actually is a working implementation. See @Steve Lazaridis Answer.
A while ago, the specification of the websockets protocol changed (the handshake process was adjusted), such that with todays browsers you cannot use the code from phpwebsockets.
Either way, in Dec 2010 there was a blog post from Christopher Blizzard, that the websocket Implementation was removed from Firefox 4. Since then I didnt follow it properly, so I can't tell you if it is currently in the browsers like Opera and Firefox. Maybe they reenabled it somehow.
I have implemented a working version some time ago, but since websockets are generally modified (was attackable with a cached poisoned dns attack) I stopped working on the implementation. So I don't know if it does work correctly now. You can read my blogpost concerning that removing and what changed in the handshake process:
http://ra23.net/wop/category/html5/
There you also can get my code and test if it works.
I suggest you to either use java or node.js websocket implementations, if they work correctly. I don't know that for sure.
Upvotes: 1
Reputation: 2210
Maybe this will help... it's another php websocket server... spoutserver
Upvotes: 0