Reputation: 61
Can I send simultaneous data to server in html5 websockets?
For example :
$(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 needs to be send to server at a time. Thanks,
Upvotes: 1
Views: 359
Reputation: 69663
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.
Upvotes: 1