protected NetBase(INetEventListener listener) { _logicThread = new NetThread("LogicThread", DefaultUpdateTime, UpdateLogic); _socket = new NetSocket(ReceiveLogic); _netEventListener = listener; _flowModes = new List <FlowMode>(); _netEventsQueue = new Queue <NetEvent>(); _netEventsPool = new Stack <NetEvent>(); NatPunchModule = new NatPunchModule(this, _socket); }
/// <summary> /// NetManager constructor /// </summary> /// <param name="listener">Network events listener</param> /// <param name="maxConnections">Maximum connections (incoming and outcoming)</param> /// <param name="connectKey">Application key (must be same with remote host for establish connection)</param> public NetManager(INetEventListener listener, int maxConnections, string connectKey) { _logicThread = new NetThread("LogicThread", DefaultUpdateTime, UpdateLogic); _socket = new NetSocket(ReceiveLogic); _netEventListener = listener; _flowModes = new List <FlowMode>(); _netEventsQueue = new Queue <NetEvent>(); _netEventsPool = new Stack <NetEvent>(); _netPacketPool = new NetPacketPool(); NatPunchModule = new NatPunchModule(this); _connectKey = connectKey; _peers = new NetPeerCollection(maxConnections); _maxConnections = maxConnections; _connectKey = connectKey; }
/// <summary> /// Stop updating thread and listening /// </summary> public virtual void Stop() { if (_running) { _running = false; _logicThread.Stop(); _logicThread = null; _socket.Close(); } }
/// <summary> /// Start logic thread and listening on selected port /// </summary> /// <param name="port">port to listen</param> public virtual bool Start(int port) { if (_running) { return false; } _netEventsQueue.Clear(); if (!_socket.Bind(port)) return false; _running = true; _logicThread = new NetThread("LogicThread(" + port + ")", UpdateTime, UpdateLogic); return true; }