public static object DeserializeType(byte[] data) { MemoryStream ms = new MemoryStream(data); BinaryReader br = new BinaryReader(ms); br.BaseStream.Position = br.BaseStream.Length - 5; // 1 byte + 1 int AdHocDesktop_SerializeType type = (AdHocDesktop_SerializeType)br.ReadInt32(); object result = null; switch (type) { case AdHocDesktop_SerializeType.AdHocDesktop_TcpObject: result = new AdHocDesktop_TcpObject(); ((IAdHocDesktop_Serializable)result).Deserialize(data); break; } return(result); }
void user_Received(object sender, AdHocDesktop_TcpObject obj) { if (src == obj.Src) { try { if (obj.Command != AdHocDesktop_TcpCommand.Ping) { object[] objs = obj.Data; byte[] buffer = objs[0].GetType() == typeof(byte[]) ? (byte[])objs[0] : null; switch (obj.Command) { case AdHocDesktop_TcpCommand.StreamingScreen: case AdHocDesktop_TcpCommand.StreamingCamera: ReceivedVideo(obj.Command, buffer); break; case AdHocDesktop_TcpCommand.StreamingAudio: ReceivedAudio(buffer); break; case AdHocDesktop_TcpCommand.ProfileScreen: case AdHocDesktop_TcpCommand.ProfileCamera: ReceivedProfile(objs); break; case AdHocDesktop_TcpCommand.EndSession: ReceivedEndSession(); break; } } } catch (Exception e) { MessageBox.Show(e.ToString()); } } }
void user_Received(object sender, AdHocDesktop_TcpObject obj) { try { AdHocDesktop_AsyncCallback ad; object[] objs = obj.Data; switch (obj.Command) { case AdHocDesktop_TcpCommand.ResponseIdentifier: ad = new AdHocDesktop_AsyncCallback(UserConnectCallback); this.BeginInvoke(ad, new object[] { objs }); break; case AdHocDesktop_TcpCommand.ResponsePeople: ad = new AdHocDesktop_AsyncCallback(UserPeopleCallback); this.BeginInvoke(ad, new object[] { objs }); break; case AdHocDesktop_TcpCommand.BeginInvitation: ad = new AdHocDesktop_AsyncCallback(UserBeginInvitationCallback); this.BeginInvoke(ad, new object[] { new object[] { objs[0], obj.Src } }); break; case AdHocDesktop_TcpCommand.EndInvitation: bool accept = (bool)objs[0]; if (accept) { ad = new AdHocDesktop_AsyncCallback(UserEndInvitationCallback); this.BeginInvoke(ad, new object[] { obj.Dest }); } break; } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
void acceptClient_Received(object sender, AdHocDesktop_TcpObject obj) { try { AdHocDesktop_TcpClient client = (AdHocDesktop_TcpClient)sender; object[] objs = obj.Data; switch (obj.Command) { case AdHocDesktop_TcpCommand.RequestIdentifier: string id = (string)objs[0]; string pw = (string)objs[1]; AdHocDesktop_ProfilePlatform platform = (AdHocDesktop_ProfilePlatform)objs[2]; bool result = false; if (id != "" && pw != "") { if (clientTable.ContainsValue(client.Identifier)) { result = false; } else { result = true; clientTable[client.Identifier] = id; if (platform == AdHocDesktop_ProfilePlatform.WINCE) { winceClients.Add(client.Identifier); } SyncPeople(); } } client.Send(new AdHocDesktop_TcpObject(AdHocDesktop_TcpCommand.ResponseIdentifier, obj.Src, obj.Dest, client.Identifier, result)); break; case AdHocDesktop_TcpCommand.RequestPeople: client.Send(new AdHocDesktop_TcpObject(AdHocDesktop_TcpCommand.ResponsePeople, obj.Src, obj.Dest, people)); break; case AdHocDesktop_TcpCommand.BeginInvitation: if (!groupTable.ContainsKey(obj.Src)) { groupTable[obj.Src] = new List <AdHocDesktop_TcpClient>(); } server.GetClient(obj.Dest).Send(new AdHocDesktop_TcpObject(AdHocDesktop_TcpCommand.BeginInvitation, obj.Src, obj.Dest, clientTable[obj.Src])); break; case AdHocDesktop_TcpCommand.EndInvitation: bool accept = (bool)objs[0]; if (accept) { AdHocDesktop_TcpClient src = server.GetClient(obj.Src); if (!groupTable[obj.Dest].Contains(src)) { groupTable[obj.Dest].Add(src); } } server.GetClient(obj.Dest).Send(new AdHocDesktop_TcpObject(AdHocDesktop_TcpCommand.EndInvitation, obj.Src, obj.Dest, accept)); break; case AdHocDesktop_TcpCommand.StreamingScreen: case AdHocDesktop_TcpCommand.StreamingCamera: case AdHocDesktop_TcpCommand.StreamingAudio: SendStreaming(client, (byte[])objs[0], obj.Command); break; case AdHocDesktop_TcpCommand.ProfileCamera: case AdHocDesktop_TcpCommand.ProfileScreen: // TODO: break; case AdHocDesktop_TcpCommand.EndSession: SendEndSession(client, obj.Command); break; case AdHocDesktop_TcpCommand.Interrupt: DisconnectClient(client); break; } } catch (Exception e) { MessageBox.Show(e.ToString()); } }