I communicate Python with Matlab via sockets. However, even before going there, I want to test sockets with netcat. So I establish server using nc -lkp 25771
, and make Python client to send a message to this server:
import socket
host = 'localhost'
port = 25771
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
s.send('Hello there')
s.close()
After running python client.py
server prints out 'Hello there'; however, after I try to run client script one more time it raises exception.
Traceback (most recent call last): File "client.py", line 13, in s.connect((host,port)) File "/usr/lib/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args) socket.error: [Errno 111] Connection refused
Why the same command raises the error second time? What changes after my first command?
-k
option to thenc
command? – falsetru