Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the Connection class and uses the already established connection.
 /// </summary>
 /// <param name="connection">An already established connection.</param>
 /// <param name="id">Id for this connection</param>
 public Connection(TcpClient connection, int id)
 {
     Id = id;
     tcpClient = connection;
     connectionStream = tcpClient.GetStream();
     streamSync = new StreamSync(connectionStream);
     streamSync.BeginReceive();
 }
Beispiel #2
0
        static void StreamClient(Stream stream)
        {
            var objsById = new Dictionary<int, StreamedObject>();
            var streamSync = new StreamSync(stream);
            streamSync.BeginReceive();

            Func<object,object> identify = (o) =>
            {
                var obj = o as StreamedObject;
                if (objsById.ContainsKey(obj.Id))
                    return objsById[obj.Id];
                else
                    return new StreamedObject();
            };

            while (true)
            {
                var updateCount = streamSync.ApplyReceivedUpdates(identify);
                if (updateCount > 0)
                    Console.WriteLine(String.Format("Received {0} updates", updateCount));
                System.Threading.Thread.Sleep(100);
            }
        }