sockets

How, in Python 3, can I have a client open a socket to a server, send 1 line of JSON-encoded data, read 1 line JSON-encoded data back, and continue?

How, in Python 3, can I have a client open a socket to a server, send 1 line of JSON-encoded data, read 1 line JSON-encoded data back, and continue? Question: I have the following code for a server listening on a port: def handle_oracle_query(self, sock, address): sockIn = sock.makefile(‘rb’) sockOut = sock.makefile(‘wb’) line = sockIn.readline() …

Total answers: 2

OSError: [Errno 57] Socket is not connected (socket programming in python macos)

OSError: [Errno 57] Socket is not connected (socket programming in python macos) Question: I have a p2p network that peers ask tracker (server) for each other port number (with udp) and make a TCP connection to each other (p2p) with tcp on the same port that they have made UDP connection with server (tracker). These …

Total answers: 2

Python: Send list of multidimensional numPy arrays over socket

Python: Send list of multidimensional numPy arrays over socket Question: i wish to send a list consisting of multi-dimensional NumPy arrays over the socket to my server and restore its format right after. The List of arrays (variable aggregated_ndarrays) looks like the following: [array([[[[-1.04182057e-01, 9.81570184e-02, 8.69736895e-02, -6.61955923e-02, -4.51700203e-02], [ 5.26290983e-02, -1.18473642e-01, 2.64136307e-02, -9.26332623e-02, -6.63961545e-02], [-8.80082026e-02, …

Total answers: 2

'[WinError 10022] An invalid argument was supplied' when using Python asyncio.loop.create_datagram_endpoint and IPv6

'[WinError 10022] An invalid argument was supplied' when using Python asyncio.loop.create_datagram_endpoint and IPv6 Question: When I execute the following script I get Send: Hello World! Error received: [WinError 10022] An invalid argument was supplied Error received: [WinError 10022] An invalid argument was supplied Connection closed import asyncio import socket class EchoClientProtocol: def __init__(self, message, on_con_lost): …

Total answers: 1

Is it ok to keep TCP connections alive throughout the serving time?

Is it ok to keep TCP connections alive throughout the serving time? Question: I’m making a socket TCP server with python that handles multiple connections simultaneously. so I defined a dictionary to hold the clients socket addresses, so I could access them and traffic the information between the clients easily. but I wander if there …

Total answers: 1

What are possible causes of my python script ending prematurely?

What are possible causes of my python script ending prematurely? Question: I have a python script that communicates with other software through TCP/IP protocol. It receives data in XML format from the software. This worked fine. However, since it is part of a larger project I packed the modules and installed them into my project …

Total answers: 1

How to make tcpClient not receive multiple message per each conn.sendall()?

How to make tcpClient not receive multiple message per each conn.sendall()? Question: Python server sender side: soc = socket.socket() hostname="localhost" port=8000 soc.bind((hostname,port)) soc.listen(1) conn , addr = soc.accept() print("device connected") cc = 0 cap = cv2.VideoCapture(0) with mp_hollistic.Holistic(static_image_mode = True ,min_detection_confidence=0.7, min_tracking_confidence=0.7) as holistic: while cap.isOpened(): ret, frame = cap.read() res, f = func(frame) val …

Total answers: 1

Python UDP socketserver returning empty message

Python UDP socketserver returning empty message Question: I have a UDP socketserver program that I use to demonstrate how UDP works (code for the server and client are below). I run this on a server, then have the client.py program send a message and receive a reply. I am unfortunately running into an issue that …

Total answers: 1

Print image on socket Termal printer (Python)

Print image on socket Termal printer (Python) Question: I’m trying to create a python script to print an image on my network connected thermal printer, through a socket connection. I tried this script but instead of printing the image it prints an infinite string of characters: import socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect(("192.168.1.56", 9100)) with …

Total answers: 1