示例#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();
 }
示例#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);
            }
        }
示例#3
0
        static void StreamServer(Stream stream)
        {
            var objsById = new Dictionary<int, StreamedObject>();
            for (int i = 0; i < 10; i++)
            {
                objsById[i] = new StreamedObject
                {
                    Id = i,
                    B = 15 * i * i
                };
            }

            var streamSync = new StreamSync(stream);

            streamSync.WriteUpdates(objsById.Values);
        }