【发布时间】:2011-11-13 20:59:02
【问题描述】:
我最近下载了http://net.tutsplus.com/tutorials/javascript-ajax/start-using-html5-websockets-today/
用于创建 PHP Web 套接字服务器的 php 类。
我已经通过命令行运行了 startDaemon,当我访问 client.php 页面时,握手被清楚地记录了:
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!
(我做了几个连接来测试)
我的问题是我似乎无法发送或接收信息。 在 php 类中,我设置了在每个点将 1,2,3... 写入日志的阶段,您可以再次通过命令窗口清楚地看到。但是当我尝试发送数据时,没有任何内容输出到日志中。
然后我去前端尝试了这个
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 没有发出警报....有人知道这里可能出了什么问题吗?
问候
【问题讨论】: