private static void Connect( CancelableTcpListener server, InboundCrossThread crossThread, MessageTransferLookUp lookUp ) { InboundMultiMessageSender sender = new InboundMultiMessageSender(); InboundMultiMessageSubscription subscription = new InboundMultiMessageSubscription(server.GetCancellationTokenSource()); server.Start(); Debug.Log("Server dispatching connections"); crossThread.AcceptStream(new NetworkMessageMultiStream(sender.GetSender(), subscription)); while (true) { var guid = server.Accept(); Debug.Log("Server connection established: " + guid); var client = server.GetClient(guid); crossThread.Schedule((parent) => { var clientSender = ConnectionWrite.Write(client, lookUp); var clientSubscription = ConnectionRead.Read(client, parent, lookUp); sender.AddClientSender(guid, clientSender); subscription.AddClientSubscription(guid, clientSubscription); }); } }
public static NetworkMessageStream Open(int port, string address, MonoBehaviour parent, MessageTransferLookUp lookUp) { var addr = IPAddress.Parse(address); var client = new CancelableTcpClient(new TcpClient(address, port)); var messageData = NetworkMessageSerializer.Get(lookUp); var recieve = ConnectionRead.Read(client, parent, lookUp); MessageHandler send = ConnectionWrite.Write(client, lookUp); return(new NetworkMessageStream(send, recieve)); }