-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
37 lines (30 loc) · 1.04 KB
/
Copy pathclient.js
File metadata and controls
37 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
;var WSClient = function () {
var webSocketsServerIP = "10.80.71.208";
var webSocketsServerPort = 1337;
var url = 'ws://'+webSocketsServerIP+':'+webSocketsServerPort+'/';
var WebSocketClient = require('websocket').client;
var wsClient = new WebSocketClient({
closeTimeout: 2000
});
init_socket = function(text){
wsClient.on('connectFailed', function(error) {
console.log('Connect Error: ' + url +' ' + error.toString());
});
wsClient.on('connect', function(connection) {
connection.on('error', function(error) {
console.log("Connection Error: " + error.toString());
});
if (connection.connected){
connection.sendUTF(text);
connection.close();
}
});
wsClient.connect('ws://'+webSocketsServerIP+':'+webSocketsServerPort, 'echo-protocol');
};
return{
SendMsg: function (text) {
init_socket(text);
}
};
}();
WSClient.SendMsg("Hola Mundo...");