Esempio n. 1
0
 public void SendPacket(CPacket packet)
 {
     if (this.clientSocket != null && this.SocketConnected(this.clientSocket))
     {
         this.clientSocket.Send(packet.ToArray(), 0, packet.Length, SocketFlags.None);
     }
 }
Esempio n. 2
0
 public void SendPacket(CPacket packet)
 {
     for(int i = 0; i < this.connections.Count; i++)
     {
         TCPConnection connection = this.connections[i];
         connection.SendPacket(packet);
     }
 }
Esempio n. 3
0
 private void CallPacketReceived(TCPConnection connection, CPacket packet)
 {
     if (this.OnPacketReceived != null)
         this.OnPacketReceived(connection, packet);
 }
Esempio n. 4
0
        private void StreamAddClick(object obj)
        {
            if(this.StreamName != string.Empty && this.StreamAddress != string.Empty)
            {
                if (this.StreamPlayer.GetCodec(this.StreamAddress))
                {
                    this.StreamManager.Streams.Add(new RadioStream() { Name = this.StreamName, Address = this.StreamAddress });
                    this.MainWindowContext.ShowMessageAsync(this.MainWindowContext.FindResource("AppName").ToString(),
                        this.MainWindowContext.FindResource("StreamAddedDialog").ToString());
                    this.StreamName = null;
                    this.StreamAddress = null;

                    if(this.CommunicationServer != null)
                    {
                        CPacket packet = new CPacket(PacketType.STREAM_LIST);
                        packet.AddByte((byte)this.StreamManager.Streams.Count);
                        for (int i = 0; i < this.StreamManager.Streams.Count; i++)
                            packet.AddString(this.StreamManager.Streams[i].Name);
                        this.CommunicationServer.SendPacket(packet);
                    }
                }
                else
                    this.MainWindowContext.ShowMessageAsync(this.MainWindowContext.FindResource("AppName").ToString(),
                        this.MainWindowContext.FindResource("StreamNotSupportedDialog").ToString());
            }
        }
Esempio n. 5
0
        void CommunicationServer_OnPacketReceived(TCPConnection connection, CPacket packet)
        {
            byte packetType = packet.GetByte();
            if(packetType == PacketType.JOIN_REQUEST)
            {
                CPacket response = new CPacket(PacketType.JOIN_RESPONSE);
                response.AddBool(true);
                connection.SendPacket(response);

                Thread.Sleep(100);

                CPacket response2 = new CPacket(PacketType.VOLUME_CONTROL);
                response2.AddByte((byte)this.Volume);
                connection.SendPacket(response2);

                Thread.Sleep(100);

                CPacket response3 = new CPacket(PacketType.STREAM_LIST);
                response3.AddByte((byte)this.StreamManager.Streams.Count);
                foreach(RadioStream stream in this.StreamManager.Streams)
                {
                    response3.AddString(stream.Name);
                }
                connection.SendPacket(response3);
            } else if(packetType == PacketType.VOLUME_CONTROL) {
                byte volume = packet.GetByte();
                this.Volume = volume;
            } else if(packetType == PacketType.PLAY_STREAM)
            {
                string streamName = packet.GetString();
                foreach (RadioStream stream in this.StreamManager.Streams)
                    if (streamName.Equals(stream.Name)) this.StreamPlayer.Play(stream.Address);
            }
        }