Questions tagged [python-sockets]

For questions related to the sockets module in the Python standard library, or more broadly socket programming in Python.

The Python library comes with a HOWTO document for sockets programming:

Socket Programming HOWTO — Python 3.x documentation

The standard library is well-documented:

socket - Low-level networking interface

Like the title suggests, sockets are the basic facility for network connections, and on Unix, several other types of interprocess connections. Beginners who want to use a particular application-level protocol should often try to find an existing higher-level library for that instead of programming directly with sockets.

506 questions
2
votes
1 answer

Python-socketio: How to emit message from server to client?

On the server, since eventlet.wsgi.server(eventlet.listen(('', 5000)), app) is blocking, the next line sio.emit('message', "hello") does not run. How do I send message from server to client? Will I have to create another thread? My server…
2
votes
1 answer

Encrypted chat app using python and RSA algorithm

I am trying to create an encrypted chat application using RSA algo in python but I am getting error messages. I am unable to find the errors in the code and the chat system is not working at all. The client.py is terminating with showing this error …
2
votes
0 answers

How to transfer real time data using python sockets (udp)

I'm trying to make an online game using both pygame and sockets. I'm new to sockets so I'm having some trouble. For now, each player is just a square that moves around the screen by command. So each player should be able to see the other player's…
Jackpy
  • 111
  • 5
2
votes
0 answers

How do I acquire a partial UDP message with Python's socket library?

I have been working with Python 2.7's socket library for a few weeks now. A request has come up where I am asked to only receive part of a message being broadcasted over UDP. The message length is dynamic, but I am trying to provide a solution to…
cwio
  • 21
  • 1
2
votes
1 answer

Maximum UDP-packet number which can be stored in the socket buffer? (Ubuntu)

Client: import socket s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) msg = b"X" for i in range(1500): s.sendto(msg,("",)) Server: import socket s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) s.bind(("",>PORT>)) counter =…
GenXGer
  • 67
  • 8
2
votes
2 answers

Python networking : find MAC address for corresponding interfaces

I has found a scripts from pmav99. Big thanks to him. import socket import psutil def get_ip_addresses(family): for interface, snics in psutil.net_if_addrs().items(): for snic in snics: if snic.family == family: …
Park Yo Jin
  • 331
  • 1
  • 3
  • 15
2
votes
1 answer

How to get the size of struct in python if the data inside struct has variable length binary string?

This code will read data from block device and pack data using struct.pack() and again unpack data using struct.unpack(). This is part of my main socket program. But I am facing an issue in calculating struct size. So I am putting a small code here…
Abhishek Verma
  • 396
  • 4
  • 14
2
votes
0 answers

Python Socket connection over 2 different networks

I know there are tons of questions like this but none of them helped me. I am trying to connect computer and vm that are on 2 different networks. Server: import socket HOST = '0.0.0.0' PORT = 1080 server_socket = socket.socket(socket.AF_INET,…
2
votes
3 answers

Python: Socket sending data at time interval

I have developed a code in which, I am reading data from serial port every second. Same data I have to send data to any IP and port but with a specific time interval like 10s,30s etc. So how to tell socket to go to sleep, that it will not send data…
Meet Adhia
  • 29
  • 1
  • 4
2
votes
1 answer

Timeout for python coroutines

How can I make a coroutine stop with timeout? I don't understand why asyncio.wait_for() doesn't work for me. I have such piece of code (planning to make my implementation of telnet client): def expect(self, pattern, timeout=20): if…
2
votes
0 answers

SocketNER freezes in Stanford NER

Or, The Mystery of Line #2598. I was trying to run Stanford-NER on a local server. I wrote some scripts, using a bit of PyNER. I then downloaded some of Sherlock Holmes' books off Project Gutenberg, and started running the program. Set up a server…
Kalpit
  • 891
  • 1
  • 8
  • 24
2
votes
1 answer

Python sock.recv not getting all data from page

this has been very hard step for me learning how to do low level socket communication but I really want to learn this, I've come to a wall and I don't seem to be able to find the proper WAY. How am I able to get all the data ? I've tried multiple…
Marie Anne
  • 301
  • 1
  • 2
  • 12
2
votes
1 answer

Python client disconnect if server closes connection

I have server and client code in python in which client sends a request message to server and wait for the response. I have the server code to close the connection when the client doesn't send a proper request. When the server closes the request,…
aBadAssCowboy
  • 2,440
  • 2
  • 23
  • 38
2
votes
2 answers

socket server - getting a connected user's ip

I have just started to make a simple socket "chat" server where users connect to my server through telnet. I was wondering how I could get the connected users IP address so that It would print out that users message like so: IP address:…
DeanMWake
  • 893
  • 3
  • 19
  • 38
2
votes
1 answer

Python socket error - recv() function

I've been trying to code a simple chat server in Python, my code is as follows: import socket import select port = 11222 serverSocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) serverSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,…
Ahmed Mohamed
  • 403
  • 2
  • 12
  • 20