Exemple #1
0
 public void Connect()
 {
     try
     {
         client = new Client(new TcpClient("10.0.0.22", 25564));
         client.Input += OnInput;
         client.Disconnect += OnDisconnect;
     }
     catch (Exception e)
     {
         Connect();
     }
 }
 public ConnectionEventArgs(Client client)
 {
     this.Client = client;
 }
Exemple #3
0
 private void acceptConnections()
 {
     listenerHandle.Start();
     while (listening)
     {
         try
         {
             TcpClient tcpc = listenerHandle.AcceptTcpClient();
             while (!canAdd) ;
             Client c = new Client(tcpc, this);
             Clients.Add(c);
             Console.WriteLine("Connection established to " + tcpc.Client.RemoteEndPoint);
         }
         catch (Exception e)
         {
             Console.WriteLine("Error in server connection acception loop:\n{0}\n{1}", e.Message, e.StackTrace);
         }
     }
     Console.WriteLine("Shutting down connection loop;");
 }
Exemple #4
0
 public void sendAll(object obj, Client excludedClient)
 {
     foreach (Client c in Clients)
     {
         if (c != excludedClient)
             c.sendObject(obj);
     }
 }
 public IOEventArgs(Client client, object obj)
 {
     this.Client = client;
     this.Object = obj;
 }
Exemple #6
0
        /// <summary>
        /// Changes the Player's current playstate to that of the packet.
        /// 
        /// If the packet was handled server-side, it will relay it to
        /// all other clients, excluding the one that sent it.
        /// </summary>
        /// <param name="playStatePacket"></param>
        /// <param name="sender"></param>
        private void HandlePlayStatePacket(PlayStatePacket playStatePacket, Client sender)
        {
            Console.WriteLine("Handling packet at {0}", DateTime.Now);
            #region Take action based on the PlayState received
            switch (playStatePacket.PlayState)
            {
                case PlayState.STOP:
                    Player.Ctlcontrols.stop();
                    break;
                case PlayState.PAUSE:
                    Player.Ctlcontrols.pause();
                    break;
                case PlayState.PLAY:
                    Player.Ctlcontrols.play();
                    break;
            }
            #endregion

            #region If hosting, relay this packet to all clients (excluding the sender)
            if (sender != null)
                if (IsHosting)
                    HostedServer.sendAll(playStatePacket, sender);
            #endregion
        }
Exemple #7
0
            private void HandleUrlPacket(UrlPacket urlPacket, Client sender)
            {
            #region Set the MediaPlayer's URL to that of the packet
            Player.URL = urlPacket.URL;
            #endregion

            #region If hosting, relay this packet to all client (excluding the sender)
            if (IsHosting)
            {
                HostedServer.sendAll(urlPacket, sender);
            }
            #endregion
        }
Exemple #8
0
        public void WatchVideo()
        {
            try
            {
                if (WatchConnection != null)
                    if (WatchConnection.isConnected())
                        WatchConnection.Dispose();

                WatchConnection = new Client(new TcpClient(WatchIP, WatchPort));
                WatchConnection.Input += OnWatchInput;
                WatchConnection.Output += OnWatchOutput;
                WatchConnection.Connect += OnWatchConnect;
                WatchConnection.Disconnect += OnWatchDisconnect;
            }
            catch (Exception e)
            {
                StopWatching();
                Debug.Log(e);
            }
        }