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
4
votes
2 answers

How to get local ip address python?

There's a code I found in internet that says it gives my machines local network IP address: hostname = socket.gethostname() local_ip = socket.gethostbyname(hostname) but the IP it returns is 192.168.94.2 but my IP address in WIFI network is…
soroushamdg
  • 191
  • 1
  • 2
  • 14
4
votes
1 answer

Python socket server can't decode redirect from OAUTH

I'm not sure how much of the code I can show, but the concept is simple. I am writing a python script that works with the TD Ameritrade API. I am getting a url for the portal from the API, and opening it in the browser. Next, I'm setting up a socket…
Amir Abbas
  • 49
  • 1
  • 8
4
votes
0 answers

When asyncio transport.get_extra_info('peername') returns None?

Sometimes my asyncio transports return None instead of IP address and port: address, port = transport.get_extra_info('peername') Here is what docs say: 'peername': the remote address to which the socket is connected, result of…
Max Malysh
  • 29,384
  • 19
  • 111
  • 115
4
votes
1 answer

Python socket server failing

I'm trying to start a UDP server in python 3. I copied the code from this example. This is my exact code. import socketserver class MyUDPHandler(socketserver.BaseRequestHandler): """ This class works similar to the TCP handler class, except…
4
votes
2 answers

Finding source IP-address when binding to 0.0.0.0

When binding a UDP socket to ("", 1234) or ("0.0.0.0", 1234), is it possible to find out what IP-address it will actually send from? As you can see in the code below, getsockname only tells me what I bound to. But when I send a packet, I can see…
csl
  • 10,937
  • 5
  • 57
  • 89
4
votes
1 answer

Why can't I receive UDP packets in Python?

I'm trying to contact an A/V device through UDP. I send a packet to local broadcast 192.168.0.255, and it responds with information about the device. I can verify it works with Wireshark. However, I never get the response in Python, it just sits…
NoBugs
  • 9,310
  • 13
  • 80
  • 146
4
votes
4 answers

Check network connection from an IP address with Python

How can I check if there is still connection from a specific ip address using python.
Nethan
  • 251
  • 1
  • 6
  • 18
4
votes
1 answer

python ftp server showing "150 File status okay. About to open data connection." and does nothing

I am trying to run an ftp server in python using pyftpdlib module. The problem occurring is that it shows a "150 File status okay. About to open data connection." and then just stays like that forever until the server time's out. I log in through…
thecreator232
  • 2,145
  • 1
  • 36
  • 51
3
votes
0 answers

python asyncio - ConnectionResetError on one async server closes also second server

I have a question regarding two async servers that run on the same event loop. when I close one connection from client side, I see that the second server stops as well. Here is my code: async def http_server(addr: str, port: int, verbose: int): …
Yaron
  • 31
  • 1
3
votes
3 answers

Handling two incoming data streams and combining them in python?

I have been researching various options in python of threading, multiprocessing async etc as ways of handling two incoming streams and combining them. There is a lot of information about, but the examples are often convoluted and complicated, and…
3
votes
1 answer

Python Port Forwarding With Sockets

I am trying to make it so that i can connect to this server from other networks around the world, as you see on the screenshot provided i have port-forwarding set up to forward all request on external port 6000 to my static ip address stored in the…
3
votes
3 answers

Unicode error for python echo server when "Ctrl+C" pressed

I have created python echo server. The echo server can be started using command sudo python3.8 echo_server.py The client can be connected to it using command telnet localhost 5000 I have implemented some commands like time,exit and network (i.e.…
cgoma
  • 47
  • 2
  • 13
3
votes
3 answers

Difference between socket.send and socket.sendall()

I've wrote two programs to test this p23_server.py for the server side and p23_client.py for the client side : p23_server.py #p23_server.py import socket HOST = '10.0.2.15' PORT = 12345 server =…
user9872569
3
votes
1 answer

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

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 to send the…
ofer026
  • 43
  • 1
  • 1
  • 5
3
votes
0 answers

ConnectionRefusedError: [Errno 111] Connection refused in python

I have python application running inside Docker container in EC2. when I deployed the container in EC2, the container crashed and it is restarting. when I looked cloudwatch logs, I got this error that the connection was refused. Traceback (most…
Ashok
  • 976
  • 3
  • 15
  • 32
1
2
3
33 34