Commit 22116217 authored by Moritz Sokoll's avatar Moritz Sokoll 💬
Browse files

Inital commit

parents
# Bird Messenger
## an open source messaging system including protocol
import socket
class ServerException(Exception):
pass
class Server:
def __init__(self, host:str, port:int):
self.socket = socket.socket(socket.AF_INET, socket.SOCKSTREAM)
self.connarray = []
self.host = host
self.port = port
def __repr__(self):
return f"message Server on: {self.host}:{self.port}"
def serve(self):
try:
self.socket.bind((self.host, self.port))
except:
raise ServerException("failed to bind socket")
while True:
conn, addr = self.socket.accept()
size = int(conn.recv(64).decode())
rawmsg = conn.recv(size).decode()
paramarray = rawmsg.split("\n")
paramdict = {}
for i in paramarray:
paramdict[i.strip().split(":")[0]] = i.strip().split(":")[1]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment