Asyncore is an asynchronous framework, as such, you don't control when you write to the network.
You have two options here:
- Use regular, synchronous sockets
- Append to the buffer instead of replacing it
The second option is quite self-explanatory, so here's how you'd do it with regular sockets:
import socket
class TestClient(object):
_buffer = ""
def __init__(self, host, port):
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host, port))
def writable(self):
return (len(self._buffer) > 0)
def write(self):
while self.writable():
sent = self.send(self._buffer)
self.buffer = self._buffer[sent:]
def link(self, name):
return name.replace(' ', '%20')
def sendArtist(self, artist):
print "here"
self._buffer = self.link(artist)
self.write()