what does means this error "broken pipe"? [duplicate] - python

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
TCP client-server SIGPIPE
I would like know what does this error mean?

You are using sockets and Http protocol.
It simply means your TCP connection has been closed by the other end or broken due to some other reason. By broken it means a 3 way handshake is required again before starting data transfer. As mentioned in the comments, being on listening end i.e. server, you normally cannot initiate the connection. So should simply close this socket and proceed ahead.
However, if you were a client, you should probably call api similar to connect again and proceed once it is successful.
Broken pipe on SO

Related

get the source IP address of a tcp connection request [duplicate]

This question already has answers here:
Refusing connection from a host
(4 answers)
How to find the source ip and port of a client that wants to connect to a listening socket?
(2 answers)
Getting the source IP address of incoming connection
(1 answer)
Deny a client's TCP connect request before accept()
(1 answer)
Closed 7 months ago.
so assume I have a socket called S, it's listening for tcp requests
IP address X sent a connection request, at this stage I have the option to accept it, but first I want to just print the IP address
there is no error I straight up don't have the slightest idea on how to do this, I tried googling, went thru the docs, nothing was of any help, thanks in advance guys

Why are there a time delay before I can reuse a opened port? [duplicate]

This question already has answers here:
Python: Binding Socket: "Address already in use"
(13 answers)
Closed 3 years ago.
When I do some programming with sockets in python
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen()
s.settimeout(0.1)
Without closing the socket before exiting the problem, the port will be unavailable for a short amount of time.
I understand that I should properly close the socket before the program exits or closed. However, during development, there are cases where the program will crash/exit before I can take care of the socket.
Why is there a time delay before I can reuse the port again? and how can I avoid such problems?
It's because of the way TCP works. From memory the connection state is TIME WAIT state.
It's purpose is to prevent delayed packets arriving on a later stream.
Set SO_REUSEADDR option when opening the socket fixes this. See answer here:
Python: Binding Socket: "Address already in use"

Python-sniffing IP packets [duplicate]

This question already has answers here:
Packet sniffing in Python (Windows)
(6 answers)
Closed 7 years ago.
What is the appropriate way in python to sniff all IP packets in real time? I'm interested in getting the raw packet data.
I've read that raw sockets are supposed to let you read some packets but didn't quite get the hang of it.
I think it make sense to use pylibpcap. Which is wrapper on Linux libcap application for package capturing.

Perofrming a python-requests Request/Reponse transaction using files rather than a socket [duplicate]

This question already has answers here:
Python requests - print entire http request (raw)?
(9 answers)
Closed 8 years ago.
I am looking for a recipe for writing and reading the raw data generated by a requests transaction from files rather than a socket. By "raw data" I mean the bytes just before they are written to or read from the underlying socket. I've tried:
Using "hooks". This seems to be mostly deprecated as the only remaining hook is "response".
mount()ing a custom Adapter. Some aggressive duck-typing here provides access to the underlying httplib.HTTPConnection objects, but the call stack down there is complicated and quite brittle.
The final solution does not need to be general-purpose as I am only interested in vanilla HTTP functionality. I won't be streaming or using the edgier parts of the protocol.
Thanks!
Spawn a thread (import threading). Run an HTTP server in there. You can generate a unique port on demand by socket.socket().bind(0). In the HTTP server, just write the incoming data to a file (perhaps named by timestamp and incoming port number). Then send your requests there.

What RPC module works over SSH, telnet and HTTP? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What RPC module should I use to implement RCP in Python and be able to change connection method later?
I am looking for RPC solution that can be used over different protocols like SSH, telnet and HTTP.
It has to be Python 2.5 compatible.
You're likely going to have to roll your own, but much of the heavy lifting in transport code could be done in other modules:
paramiko for ssh
telnetlib for telnet
urllib(2) for http.
You'll still have to address the issue of data format, but that is independent of transport protocol (feel free to deliver XML-RPC or JSON or any other format over these transports).

Categories