I'm experimenting a little with creating a socket server, in PHP. In doing so I'm trying to abstract away the kinds of sockets I think I'll be needing, that I've tentitively named:ListenSocket  the 'master' socket, that is bound to an address/port and listens for and accepts incoming connections.CommunicationSocket  a 'child' socket, that represents an accepted, incoming connection, which the server will communicate with.As the name already kind of implies, I will only define read() and write() type of methods on the CommunicationSocket.However, doing so got me wondering: does it ever make sense to read from or write to the first type of socket (the bound, listening type)?
Does it ever make sense to read from and/or write to a bound, listening socket?
sockets;client server;io
I interpret your question in a way that you refer to TCP/IP sockets. With UDP/IP sockets it is different.Two scenarios:Scenario 1: 1. bind 2. connect 3. listenResult: You cannot listen at a connected socket.>>> 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 socketScenario 2: 1. bind 2. listen 3. connectResult: You can not connect or send at a listening socket.>>> 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(b123)Traceback (most recent call last):  File <pyshell#137>, line 1, in <module>    s.send(b123)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