Hello,
I have a trouble to do what i want.
I'm not a Python developper...
I have a software who can provide me somme data, but, this software can only send data on a RAW style TCP port in local network.
So i search on internet how to listen data on a specific port (1234) of my computer.
I manage to get the data.
The in another code i try to send test data in my websocket. it is working fine.
My goal now is to send all data to my websocket.
I merge the two code, it work, but i assume i'm not doing it right. Because every time my python script send data to the websocket he open, send and close the websocket.
My code work but after a little time i have a 20 seconds delta between the time i send data and retreive it on my web socket ...
I try to call the websocket after but my code note working ...
There is the code who work at home. But full of problems
(too long, not optimised, and when websocket is off, the script shutdown him sefl and not try to reconnect on it ...)

hi @snippsat i'm sorry i put my message in the wrong section, coul'd you move it in the Network forum ? thank you !
I have a trouble to do what i want.
I'm not a Python developper...
I have a software who can provide me somme data, but, this software can only send data on a RAW style TCP port in local network.
So i search on internet how to listen data on a specific port (1234) of my computer.
I manage to get the data.
The in another code i try to send test data in my websocket. it is working fine.
My goal now is to send all data to my websocket.
I merge the two code, it work, but i assume i'm not doing it right. Because every time my python script send data to the websocket he open, send and close the websocket.
My code work but after a little time i have a 20 seconds delta between the time i send data and retreive it on my web socket ...
I try to call the websocket after but my code note working ...
There is the code who work at home. But full of problems
(too long, not optimised, and when websocket is off, the script shutdown him sefl and not try to reconnect on it ...)
import socket
import asyncio
import websockets
import json
async def send(client, data):
await client.send(data)
def server_program():
host = socket.gethostname()
port = 1234
server_socket = socket.socket()
server_socket.bind((host, port))
server_socket.listen(2)
conn, address = server_socket.accept()
print("Connection de: " + str(address))
while True:
data = conn.recv(1024).decode()
if not data:
# if data is not received break
break
print("Balises: " + str(data))
# Send data to our websocket
async def hello():
async with websockets.connect('wss://mywebsocketServer') as websocket:
await websocket.send(json.dumps({"RAW_DATA": str(data) }))
asyncio.get_event_loop().run_until_complete(hello()) # this close the websocket communication
conn.close() # close the connection
if __name__ == '__main__':
server_program()
async def send(client, data):
await client.send(data)I hope you can help me !
hi @snippsat i'm sorry i put my message in the wrong section, coul'd you move it in the Network forum ? thank you !
