Thursday, 18 July 2019

I'm having trouble sending and receiving socket messages in Node, like I am able to do in Python.

I have a project where I send/receive messages to an Arduino (through an ethernet to serial converter) to measure data. I have successfully implemented it in Python using the socket library.But there is one function that I need to call from an Angular web app, so I will need to do the same thing in Node.But I can't seem to find any similar examples of what I'm doing using the socket.io library. What's the best way to achieve this using this library?Here is the part of the Python code that handles the communication.def send(ip): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) message = "sendmessagedata\n" try: s.settimeout(2) s.connect((ip, 2000)) s.send(reqReadMsg.encode()) result = s.recv(256) print(result.decode()) return result.decode(), True except (socket.timeout,ConnectionResetError,socket.error) as c: print(c) s.close() return c, False

Submitted July 19, 2019 at 03:28AM by codie28

No comments:

Post a Comment