python-sockets

Python Socket accept() Timeout

Python Socket accept() Timeout Question: Using sockets, the below Python code opens a port and waits for a connection. Then, it sends a response when a connection is made. import socket ip = 127.0.0.1 port = 80 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((ip, port)) s.listen(1) conn, addr = s.accept() conn.send(response) conn.close() If a …

Total answers: 2

What is `conn, addr = s.accept()` in python socket?

What is `conn, addr = s.accept()` in python socket? Question: I searched documentations and tutorials but no one talked about this, for example this is server script import socket server = socket.socket() print("socket created") server.bind(("localhost", 9999)) server.listen(3) print("waiting for connection") while True: client, addr = server.accept() print(client) print(addr) name = client.recv(1024).decode() print("connected with", addr, client, …

Total answers: 4

How to send messages to a remote computer using python socket module?

How to send messages to a remote computer using python socket module? Question: I’m trying to send a message from a computer to a another computer that is not connected to the other computer local network. I did port forwarding (port 8080, TCP) and I didn’t manage to get the remote computer to connect and …

Total answers: 2

Getting 127.0.1.1 instead of 192.168.1.* ip ubuntu python

Getting 127.0.1.1 instead of 192.168.1.* ip ubuntu python Question: I am new to python. I want to get the ipaddress of the system. I am connected in LAN. When i use the below code to get the ip, it shows 127.0.1.1 instead of 192.168.1.32. Why it is not showing the LAN ip. Then how can …

Total answers: 6

Python requests speed up using keep-alive

Python requests speed up using keep-alive Question: In the HTTP protocol you can send many requests in one socket using keep-alive and then receive the response from server at once, so that will significantly speed up whole process. Is there any way to do this in python requests lib? Or are there any other ways …

Total answers: 1