But now encounter problems as follows,
When web client sends data to the server, using the send () method, which successfully sent, web side will disconnect the socket?
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Basically is to press
https://my.oschina.net/u/4414234/blog/3351970
The following program this verse,
Now the case is called WebSocketSendMsg, after sending the socket connection is broken, and then automatically connected again, the pop-up interface alert (" already open connection!" );
Don't know how to modify, the great god give directions!!!!!!!!!! Thank you thank you
<script>
Var webSocket={};
//create websockt
The function CreateWebSocket () {
WebSocket=new webSocket (ws://127.0.0.1: "8002");
WebSocket. Onopen=WebSokectOnOpen;
WebSocket. Onmessage=WebSocketOnMessage;
WebSocket. Onclose=WebSocketOnClose;
};
//connect events
The function WebSokectOnOpen () {
//alert (" already open connection!" );
WebSocket. Send (" Open ");
};
//to monitor events
The function WebSocketOnMessage (event) {
//to monitor data from the service
Alert (event. The data);
};
The function WebSocketOnClose () {
//to monitor data from the client's
Alert (" Close ");
};
//send events
The function WebSocketSendMsg () {
//get the values in the text
Var text=document. GetElementById (" Text1 "). The value;
//sent to the server
WebSocket. Send (text);
};
</script>