I wrote a electrum client in python.
import asyncore,socket
class electrum(asyncore.dispatcher):
def __init__(self,ip,port):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET,socket.SOCK_STREAM)
self.connect((ip,port))
self.buffer='{"id":0,"method":"server.version","params":["2.5","0.9"]}\n'
self.re=""
def handle_connect(self):
pass
def handle_close(self):
self.close()
def handle_read(self):
self.re=self.recv(8192)
print self.re
def writable(self):
return (len(self.buffer)>0)
def handle_write(self):
sent=self.send(self.buffer)
print self.buffer[:sent]
self.buffer=self.buffer[sent:]
e=electrum("electrum.neocrypto.io",50002)
e.buffer+='{"id":1,"method":"blockchain.headers.subscribe","params":[]}\n'
asyncore.loop()
it gets response from coinomi server, but other server gives no response and close the connection.
I am confused what I am doing wrong?