Interpreto la tua domanda in modo da farti riferimento ai socket TCP / IP. Con i socket UDP / IP è diverso.
Due scenari:
Scenario 1: 1. bind 2. connessione 3. ascolta
Risultato: non è possibile ascoltare su un socket collegato.
>>> import socket
>>> s = socket.socket()
>>> s.bind(('', 0))
>>> s.send(b'a')
Traceback (most recent call last):
File "<pyshell#130>", line 1, in <module>
s.send(b'a')
OSError: [WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
>>> s.connect(('google.de', 80))
>>> s.listen(1)
Traceback (most recent call last):
File "<pyshell#132>", line 1, in <module>
s.listen(1)
OSError: [WinError 10056] A connect request was made on an already connected socket
Scenario 2: 1. bind 2. listen 3. connect
Risultato: non è possibile connettersi o inviare in una presa di ascolto.
>>> s = socket.socket()
>>> s.bind(('', 0))
>>> s.listen(1)
>>> s.connect(('google.de', 80))
Traceback (most recent call last):
File "<pyshell#136>", line 1, in <module>
s.connect(('google.de', 80))
OSError: [WinError 10022] An invalid argument was supplied
>>> s.send(b"123")
Traceback (most recent call last):
File "<pyshell#137>", line 1, in <module>
s.send(b"123")
OSError: [WinError 10057] A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied