我想在第一次连接到套接字服务器时发送params。
我正在寻找一种发送方法,如:
var wsUrl = 'ws://localhost:9300',
wsHandle = new WebSocket(wsUrl, [myParam]);
或类似:
var wsUrl = 'ws://localhost:9300',
wsHandle = new WebSocket(wsUrl, {
myKey: myParam
});
有人帮我写一些关键词吗?谢谢你的回答。
我假设你的意思是你想在连接时发送一些东西?
var socket;
function OpenSocket() {
if (window.hasOwnProperty("WebSocket")) { // webkit-browser
socket = new WebSocket("ws://localhost:12345/");
}
else if (window.hasOwnProperty("MozWebSocket")) { // firefox
socket = new MozWebSocket("ws://localhost:12345/");
}
else { // browser doesnt support websockets
alert("Your browser doesn't support WebSocket.");
return;
}
socket.onopen = function() { // the socket is ready, send something
//socket.send("Testing websocket data flow...");
};
}