public PacketProtocol(NetworkStream stream, PacketQueue packetQueue) { this.stream = stream; this.packetQueue = packetQueue; writer = new BinaryWriter(stream); reader = new BinaryReader(stream); }
public Client(string host, int port, PacketQueue packetQueue) { this.host = host; this.port = port; this.packetQueue = packetQueue; Thread thread = new Thread(RunMain); thread.Name = "Server Connection"; thread.IsBackground = true; thread.Start(); }
/// <summary> /// Initialize component, or destroy if an active instance of it already /// exists. /// </summary> void Awake() { if (net != null) { Destroy(this); return; } net = this; DontDestroyOnLoad(net); packetExecutor = GetComponent <IPacketExecutorContext>(); packetQueue = new PacketQueue(); client = new Client("localhost", port, packetQueue); }
public void Stop() { if (!IsRunning) { return; } lock (tcp) { Debug.Log("Stopping client..."); stream.Close(); tcp.Close(); // Drop all memory tcp = null; stream = null; packetQueue = null; packetProtocol = null; } }