multi-user/net_components.py

45 lines
1.1 KiB
Python
Raw Normal View History

import zmq
2019-02-04 13:53:38 +01:00
# from zmq.asyncio import Context, ZMQEventLoop
# import asyncio
2019-01-25 17:02:04 +01:00
from enum import Enum, auto
class Role(Enum):
2019-01-25 17:02:04 +01:00
NONE = 'NONE'
SERVER = 'SERVER'
CLIENT = 'CLIENT'
def __str__(self):
return self.value
class Replication(Enum):
2019-01-25 17:02:04 +01:00
NONE = auto()
REPLICATED = auto()
REPNOTIFY = auto()
2019-01-25 10:11:40 +01:00
class User:
def __init__(self, name="default", ip="localhost",role=Role.NONE):
2019-01-25 10:11:40 +01:00
self.name = name
self.role = role
2019-01-25 10:11:40 +01:00
class NetworkInterface:
2019-02-04 13:53:38 +01:00
def __init__(self, host="*",context=None, socket_type=zmq.REQ,protocol='tcp',port=5555):
2019-01-25 10:11:40 +01:00
self.host = host
self.context = context
self.socket = context.socket(socket_type)
2019-01-25 17:28:53 +01:00
self.poller = zmq.Poller()
#TODO: Is this right to it here?
2019-01-25 17:28:53 +01:00
self.poller.register(self.socket, zmq.POLLIN)
2019-02-04 13:53:38 +01:00
print("{}://{}:{}".format(protocol,host,port))
self.socket.bind("tcp://*:5555")
2019-01-25 10:11:40 +01:00
class Property:
def __init__(self, property=None, replication=Replication.NONE):
2019-01-25 10:11:40 +01:00
self.property = property
self.replication = replication
2019-01-25 10:11:40 +01:00
class Function:
def __init__(self, function=None):
self.function = function