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
1
vote
1 answer

Get IP of connected client in python

is there a way to get the IP of the connected client? (And if possible the port it uses). I tried client_socket.getsockname() but it gave me my IP address.
Netanel
  • 477
  • 2
  • 11
1
vote
1 answer

Find ips listening on a port with python

How can python help accept a specific port number from a user as input and return all the ips listening on that port on the system. The python script could be running locally on a linux system where this is needed or may access the linux system…
codecrazy46
  • 275
  • 1
  • 5
  • 14
1
vote
1 answer

Python socket can not seem to make a connection

I'm trying to make a TCP chat on port 10 000, I have a linux server on which I'm listening : NETSTAT report : tcp 0 0 127.0.0.1:10000 0.0.0.0:* LISTEN NMAP report : 10000/tcp open snet-sensor-mgmt But I can not…
Tim
  • 394
  • 2
  • 14
1
vote
0 answers

I want to make a server that returns text and image at the same time, only using python socket and not using modules like simplehttpserver

Problem is that I cannot get my image files Should I encode image files to binaryarras? How can I put use utf-8 and base64 at the same time to make image and text show up at the same time... ## import socket import base64 server_socket =…
1
vote
0 answers

How to enable promiscuous mode with Python sockets on Mac OS X

I've searched everywhere and can't seem to find out how to enable promiscuous mode on my Mac. I would like to use Python sockets to do it.
DavidL
  • 75
  • 7
1
vote
1 answer

Python socket recv waits for send if using getch?

This is a very unexpected behavior: Here is a textbook classic short program that uses one thread to get characters one by one from a socket stream and display it, and a second thread to read input and send the input over the same socket…
QT-1
  • 900
  • 14
  • 21
1
vote
1 answer

Python sockets [WinError 10038] An operation was attempted on something that is not a socket

This is not a duplicate. I have searched for literally hours to find the answer and no luck so I'm asking here. I am currently building a chat server using python's socket module. When I run the server, after the client connects and the server says…
Joe Evans
  • 26
  • 1
  • 1
  • 6
1
vote
1 answer

What does the socket.bind method do?

I have this script that, when it's restarted (forced), it prints a different IP/port of connection (using socket module). The thing is: a want a permanent connection (sure, when it doesn't restart). The function bind works exactly with this purpose?
CSS Monteiro
  • 71
  • 1
  • 1
  • 8
1
vote
3 answers

TypeError: str, bytes or bytearray expected, not list

So I am trying to pull some IP's from a text file and using that list in the socket connection. My issue is I keep getting the following error: TypeError: str, bytes or bytearray expected, not list Here is the code im using: import socket …
pylearning
  • 41
  • 1
  • 6
1
vote
0 answers

python ftplib timeouts on upload, does not resume

I am using the following code to upload large files over a flaky FTP, which also is able to resume the upload if there is an error. #!/usr/bin/env python3 import ftplib import os import sys import time import socket from configparser import…
GuySoft
  • 1,723
  • 22
  • 30
1
vote
1 answer

How to run interactive commands using python tcp socket?

Say if I wanted to run vim ./foo.txt I want to be able to edit foo.txt with my tcp socket client. But whenever I try to do this it executes on the server but not on my client. I do not want to use paramiko or any other ssh-like modules I want to…
user9249376
1
vote
1 answer

How to recieve files from a server in python?

I Have made a python script, where you can send files to a remote server and receive them. I can send them to the server but can not seem to retrieve them back I've attached both server and client.py Server.py import socket # Import socket…
1
vote
1 answer

How can I convert an byte array to PNG image and save it to a specific folder?

I am trying to convert an byte array to PNG image and save it to a specific folder. The byte array comes from a C# server, python client will receive it and save as PNG image. I tried the following way: reply = s.recv(4096) image =…
1
vote
0 answers

Python WebSocket Channel - Connection reset by peer

I want to build my own library to be used for server -> browser communicating via websockets. I have tried to build something, it's here: https://github.com/duverse/wsc. But sometimes, when I trying to make API Call to my own server, I've got…
1
vote
1 answer

Python socketIO-client connects and then disconnects

I am trying to connect my python script to my nodejs socket server. My code looks like this- node js (relevant part)- //using socket.io@2.0.3 //PORT 8008 io.on('connection', function(socket){ console.log('connected'); socket.on('disconnect',…
aquaman
  • 1,523
  • 5
  • 20
  • 39