Working simple client/server
This commit is contained in:
parent
0d33aacf3f
commit
e155420a4b
3 changed files with 82 additions and 4 deletions
29
datajack/__init__.py
Normal file
29
datajack/__init__.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import socket
|
||||
import urllib.parse
|
||||
|
||||
class Connection:
|
||||
def __init__(self, uri):
|
||||
parts = urllib.parse.urlparse(uri)
|
||||
netloc = parts.netloc
|
||||
self.host, _, self.port = netloc.partition(":")
|
||||
|
||||
|
||||
def __enter__(self):
|
||||
self.connect()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_typ, exc_val, exc_tb):
|
||||
pass
|
||||
|
||||
def connect(self):
|
||||
self.socket = socket.socket()
|
||||
self.socket.connect((self.host, int(self.port)))
|
||||
|
||||
def disconnect(self):
|
||||
pass
|
||||
|
||||
def send(self, data):
|
||||
self.socket.send(data)
|
||||
|
||||
def connection(uri) -> Connection:
|
||||
return Connection(uri)
|
Loading…
Add table
Add a link
Reference in a new issue