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(); } } } }
public void DataProcessing(int userID, byte operation, byte[] data) { UserModel user = Users.Find(obj => obj.ID == (int)(userID & 0xFFFFFFFC)); switch (userID & 3) { case 0: switch (operation) { case 0: UserModel newUser = ConvertClass.ByteArrayToObject(data) as UserModel; newUser.VoiceFrame = new AudioOutput(); Users = CollectionConversion.ConcatList <UserModel>(users, new List <UserModel>() { newUser }); break; case 1: Users = CollectionConversion.ConcatList <UserModel>(users, ConvertClass.ByteArrayToObject(data) as List <UserModel>); foreach (var value in Users) { value.VoiceFrame = new AudioOutput(); } break; case 2: PropertyInfo property = ConvertClass.ByteArrayToObject(data) as PropertyInfo; property.SetValue(user, !(bool)property.GetValue(user)); break; case 3: mainVM.CurrentViewModel = new MenuViewModel(mainVM); break; case 4: Users = (ConvertClass.ByteArrayToObject(data) as List <UserModel>).FindAll(obj => obj.ID != uniqueID); break; } break; case 1: if (user.IsWebcam != false || user.IsScreenDemonstration != false) { user.CurrentFrame = new Bitmap(new MemoryStream(data)); } break; case 2: if (MyModel.IsSpeaker) { user.VoiceFrame.AddData(data); } break; } }
public void SendData(byte[] data, byte operation, int uniqueID) { try { data = CollectionConversion.AddToEndArray(CollectionConversion.AddToEndArray(data, new byte[] { operation }), BitConverter.GetBytes(uniqueID)); threads[uniqueID].GetStream().Write(data, 0, data.Length); } catch { } }
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; } }
private void DataConversion(byte[] source) { var(userID, operation, data) = CollectionConversion.GetSenderInformation(source); chatRoomVm.DataProcessing(BitConverter.ToInt32(userID, 0), operation, data); }