public ChatRoomViewModel(MainViewModel mainVM, string ip, int remotePort, Server server)
        {
            this.mainVM = mainVM;
            this.server = server;
            uniqueID    = (int)(GetHashCode() & 0xFFFFFFFC);

            myModel = new UserModel(uniqueID, mainVM.Name);
            client  = new Client(ip, remotePort, uniqueID, this);
            client.SendData(ConvertClass.ObjectToByteArray(myModel), 0, uniqueID + 0);
            users            = new List <UserModel>();
            webcam           = new Webcam((new FilterInfoCollection(FilterCategory.VideoInputDevice))[0]);
            webcam.NewFrame += (sender, e) =>
            {
                if (myModel.IsScreenDemonstration != true)
                {
                    client.SendData(ConvertClass.ConvertBitmapToByte((Bitmap)e.Frame.Clone()), 0, uniqueID + 1);
                }
            };
            audioRecord = new AudioRecord(0);
            audioRecord.DataAvailable += (sender, e) =>
            {
                client.SendData(e.Buffer, 0, uniqueID + 2);
            };
            demonstration           = new ScreenDemonstration();
            demonstration.NewFrame += (sender, e) =>
            {
                client.SendData(ConvertClass.ConvertBitmapToByte((Bitmap)e.Frame.Clone()), 0, uniqueID + 1);
            };
        }
Beispiel #2
0
 private void GetData(TcpClient client)
 {
     try
     {
         NetworkStream stream = client.GetStream();
         while (true)
         {
             using (MemoryStream ms = new MemoryStream())
             {
                 int    bytes = 0;
                 byte[] data  = new byte[65536];
                 do
                 {
                     bytes = stream.Read(data, 0, data.Length);
                     ms.Write(data, 0, bytes);
                 }while (stream.DataAvailable);
                 SendData(client, ms.ToArray());
             }
         }
     }
     catch
     {
         if (isRunning)
         {
             if (client.Connected)
             {
                 clientInfo.Remove(clientInfo.Find(obj => obj.ID == (int)(clients[client] & 0xFFFFFFFC)));
                 SendData(client, CollectionConversion.AddToEndArray(CollectionConversion.AddToEndArray(ConvertClass.ObjectToByteArray(clientInfo), new byte[] { 4 }), new byte[4]));
                 clients.Remove(client);
                 client.Close();
             }
         }
     }
 }
Beispiel #3
0
        private void DataProcess(TcpClient client, byte[] source)
        {
            var(userID, operation, data) = CollectionConversion.GetSenderInformation(source);
            switch (operation)
            {
            case 0:
                var listData = CollectionConversion.AddToEndArray(CollectionConversion.AddToEndArray(ConvertClass.ObjectToByteArray(clientInfo), new byte[] { 1 }), userID);
                client.GetStream().Write(listData, 0, listData.Length);
                clientInfo.Add(ConvertClass.ByteArrayToObject(data) as UserModel);
                break;

            case 2:
                UserModel    user     = clientInfo.Find(obj => obj.ID == BitConverter.ToInt32(userID, 0));
                PropertyInfo property = ConvertClass.ByteArrayToObject(data) as PropertyInfo;
                property.SetValue(user, !(bool)property.GetValue(user));
                break;
            }
        }