是否可以连接到多个 html5 websocket 连接?因为我想有一个用于读取的 websocket 连接和用于写入套接字的其他 websocket 连接。我想在同一时间使用不同的连接 ID 打开。
例如:
$(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');
conn2 = new WebSocket('ws://ip1:8102');
//connection open
conn1.onopen = function () {
conn1.send("Connection1 Established Confirmation");
};
conn2.onopen = function () {
conn2.send("Connection2 Established Confirmation");
};
}