1

我可以在 html5 websockets 中同时向服务器发送数据吗?

例如 :

$(document).ready(function () {
    conn = {}, window.WebSocket = window.WebSocket || window.MozWebSocket;     
    connection1();
});

function connection1() {
    // uses global 'conn' object
    if (conn.readyState === undefined || conn.readyState > 1) {
        conn1 = new WebSocket('ws://ip1:8101');

        //connection open 
        conn1.onopen = function () {
            conn1.send("Connection1 Established Confirmation");
        }
    };

    conn1.onmessage = function(message){
        conn1.send("data1");
        conn1.send("data2");
        conn1.send("data3");
        conn1.send("data4");
    };
}

data1,data2,data3,data4 需要一次发送到服务器。谢谢,

4

1 回答 1

1

Web socket sends are always asynchronous. When you call send four times, these will be sent immediately and the program will continue without waiting for an acknowledgment from the server.

They will, however, reach the server as separate messages. When you want one message data1data2data3data4, you have to do this in one send.

于 2013-07-10T11:52:24.597 回答