Your server accepts connections and then drops them on the floor:
def handle_accept(self):
pair = self.accept()
if pair is not None:
sock, addr = pair
print ('Incoming connection from %s' % repr(addr))
The server socket is separate from each of the connections accepted by the server socket.
If you want to read bytes from the connection then you have to do some more work to handle read events on it.
I suggest taking a look at Twisted instead. It is more actively maintained, better documented, and more featureful than asyncore. Here's a minimal Twisted-based example that does what I think you want your app to do:
tx_client.py
from twisted.internet.task import react
from twisted.internet.defer import Deferred
from twisted.internet.protocol import Protocol
from twisted.internet.endpoints import clientFromString, connectProtocol
class SendBytes(Protocol):
def __init__(self, data):
self.data = data
self.done = Deferred()
def connectionMade(self):
self.transport.write(self.data)
self.transport.loseConnection()
def connectionLost(self, reason):
self.done.callback(None)
def main(reactor, description, data):
endpoint = clientFromString(reactor, description)
connecting = connectProtocol(endpoint, SendBytes(data))
def connected(proto):
print("Successfully connected to {0}".format(proto.transport.getPeer().host))
return proto.done
connecting.addCallback(connected)
return connecting
if __name__ == '__main__':
react(main, [b"tcp:host=127.0.0.1:port=4444", b"DDDDDD"])
tx_server.py
from twisted.internet.task import react
from twisted.internet.defer import Deferred
from twisted.internet.protocol import Factory, Protocol
from twisted.internet.endpoints import serverFromString
class ReadBytes(Protocol):
def connectionMade(self):
print("Incoming connection from {}".format(self.transport.getPeer()))
def dataReceived(self, data):
print("Received {}".format(data))
def main(reactor, description):
endpoint = serverFromString(reactor, description)
endpoint.listen(Factory.forProtocol(ReadBytes))
return Deferred()
if __name__ == '__main__':
react(main, [b"tcp:interface=127.0.0.1:port=4444"])