Is there a way to do a tcp connection to an IP with javascript?

前端 未结 3 409
名媛妹妹
名媛妹妹 2021-01-13 03:13

Let me give a little background on what I am trying to accomplish.

I have a device(chip and pin Terminal) that has a local IP address, It has been programmed to rece

3条回答
  •  借酒劲吻你
    2021-01-13 03:43

    Have you tried to use like this:

    var exampleSocket = new WebSocket('wss://IP:PORT', ['soap', 'xmpp']);
    
    // When the connection is open, send some data to the server
    exampleSocket.onopen = function () {
      exampleSocket.send('05'); 
    };
    
    // Log errors
    exampleSocket.onerror = function (error) {
      console.log('WebSocket Error ' + error);
    };
    
    // Log messages from the server
    exampleSocket.onmessage = function (e) {
      console.log('Server: ' + e.data);
    };
    

    hope I could be helpfull!

提交回复
热议问题