Skip to content

Instantly share code, notes, and snippets.

@harsh-98
Last active June 15, 2020 15:06
Show Gist options
  • Save harsh-98/18e19e467d7f2bf9c5745af2db68457c to your computer and use it in GitHub Desktop.
Save harsh-98/18e19e467d7f2bf9c5745af2db68457c to your computer and use it in GitHub Desktop.
import socket
class MySocket:
def __init__(self, sock=None):
if sock is None:
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
else:
self.sock = sock
def connect(self, host, port):
self.sock.connect((host, port))
def mysend(self, msg):
self.sock.send(msg.encode('utf-8'))
def myreceive(self):
return self.sock.recv(4096)
msg='{"jsonrpc": "2.0","method": "nodeStats", "id": "1"}\n'
s = MySocket()
s.connect("127.0.0.1", 21338)
s.mysend(msg)
print(s.myreceive())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment