/// <summary> /// Add the given connection to our list of clients /// Note we have a new friend /// Send a welcome to the new client /// Setup a callback to recieve data /// </summary> /// <param name="sockClient">Connection to keep</param> //public void NewConnection( TcpListener listener ) public void NewConnection(Socket sockClient) { // Program blocks on Accept() until a client connects. //SocketChatClient client = new SocketChatClient( listener.AcceptSocket() ); SocketControlClient client = new SocketControlClient(sockClient); m_aryClients.Add(client); Console.WriteLine("Client {0}, joined", client.Sock.RemoteEndPoint); // Get current date and time. String strDateLine = "NOONCE|" + this.keySerect; // Convert to byte array and send. Byte[] byteDateLine = System.Text.Encoding.ASCII.GetBytes(strDateLine.ToCharArray()); client.Sock.Send(byteDateLine, byteDateLine.Length, 0); client.SetupRecieveCallback(this); }
/// <summary> /// Get the new data and send it out to all other connections. /// Note: If not data was recieved the connection has probably /// died. /// </summary> /// <param name="ar"></param> public void OnRecievedData(IAsyncResult ar) { SocketControlClient client = (SocketControlClient)ar.AsyncState; byte[] aryRet = client.GetRecievedData(ar); if (aryRet.Length < 1) { Console.WriteLine("Client {0}, disconnected", client.Sock.RemoteEndPoint); client.Sock.Close(); m_aryClients.Remove(client); return; } string str = System.Text.Encoding.Default.GetString(aryRet); Console.WriteLine(str); if (client.type == TYPE.NONE) { string[] dataStr = str.Split('_'); bool flag = this.CheckControl(ref client, dataStr); if (!flag) { client.Sock.Send(getByteText("FAIL|200|CONTROL")); client.Sock.Close(); m_aryClients.Remove(client); } else { client.Sock.Send(getByteText("OK|200|CONTROL")); client.SetupRecieveCallback(this); } } else { #region Comment // if (dataStr.Length > 1 & dataStr[0].ToUpper() == "ADMIN") // { // if (CommonUtilities.checkAdminColtrol(dataStr[1])) // { // client.flag_admin_Control = true; // client.flag_can_Coltrol = true; // client.Sock.Send(getByteText("OK|200|ADMIN")); // client.SetupRecieveCallback(this); // } // else // { // client.flag_can_Coltrol = false; // client.Sock.Send(getByteText("FAIL|205|ADMIN")); // client.Sock.Close(); // m_aryClients.Remove(client); // } // } // else // { // if (CommonUtilities.userColtrol.checkLoginNetWork(CommonUtilities.keySerect,str) && flag_login_user) // { // client.flag_admin_Control = false; // client.flag_can_Coltrol = true; // client.Sock.Send(getByteText("OK|200")); // client.SetupRecieveCallback(this); // } // else // { // client.flag_admin_Control = false; // client.flag_can_Coltrol = false; // client.Sock.Send(getByteText("FAIL|205")); // client.Sock.Close(); // m_aryClients.Remove(client); // } // } //} //else //{ // if (client.flag_admin_Control) // { // if (str.ToUpper() == "PLAY") // { // this.adminControl = _controlVLC._CONTROL_PLAY; // this.PlayVlc(this, client.Sock.RemoteEndPoint); // } // else if (str.ToUpper() == "PAUSE") // { // this.adminControl = _controlVLC._CONTROL_PAUSE; // } // else if (str.ToUpper() == "STOP") // { // this.adminControl = _controlVLC._CONTROL_STOP; // this.StopVlc(this, client.Sock.RemoteEndPoint); // } // else if (str.ToUpper() == "NEXT") // { // this.adminControl = _controlVLC._CONTROL_NEXT; // } // else if (str.ToUpper() == "BACK") // { // this.adminControl = _controlVLC._CONTROL_BACK; // } // else if (str.ToUpper() == "STREAM") // { // this.adminControl = _controlVLC._CONTROL_STREAM; // this.ipHostStream = parseIP(client.Sock.RemoteEndPoint); // if (PlayStreaming != null) // { // PlayStreaming(this, this.ipHostStream); // } // } // else if(str.ToUpper()=="ABORT") // { // this.adminControl = _controlVLC._CONTROL_ABORT_USER; // } // else if (str.ToUpper() == "ACCEPT") // { // this.adminControl = _controlVLC._CONTROL_ACCEPT_USER; // } // else if (str.ToUpper() == "SCREEN") // { // if (SendPlaying != null) // { // SendPlaying(this, client.Sock.RemoteEndPoint); // } // this.adminControl = _controlVLC._CONTROL_SCREEN; // } // else if (str.ToUpper() == "TURN_OFF") // { // this.adminControl = _controlVLC._CONTROL_OFF; // if(this.TurnOffApp!=null) // TurnOffApp(this, client.Sock.RemoteEndPoint); // } // else if (str.ToUpper() == "STOPSTREAM") // { // this.dataControl = _controlVLC._CONTROL_STREAM_STOP; // if (StopStreaming != null) // StopStreaming(this, new EventArgs()); // } // else // { // this.adminControl = _controlVLC._CONTROL_FREE; // } // } // else // { // if (str.ToUpper() == "PLAY") // { // this.dataControl = _controlVLC._CONTROL_PLAY; // if (this.PlayVlc!=null) // { // this.PlayVlc(this, client.Sock.RemoteEndPoint); // } // } // else if (str.ToUpper() == "PAUSE") // { // this.dataControl = _controlVLC._CONTROL_PAUSE; // } // else if (str.ToUpper() == "STOP") // { // this.dataControl = _controlVLC._CONTROL_STOP; // if (this.StopVlc != null) // { // this.StopVlc(this, client.Sock.RemoteEndPoint); // } // } // else if (str.ToUpper() == "NEXT") // { // this.dataControl = _controlVLC._CONTROL_NEXT; // } // else if (str.ToUpper() == "BACK") // { // this.dataControl = _controlVLC._CONTROL_BACK; // } // else if (str.ToUpper() == "STREAM") // { // this.dataControl = _controlVLC._CONTROL_STREAM; // this.ipHostStream = parseIP(client.Sock.RemoteEndPoint); // if (PlayStreaming != null) // { // PlayStreaming(this, this.ipHostStream); // } // } // else if (str.ToUpper() == "SCREEN"){ // if (SendPlaying != null) // { // SendPlaying(this, client.Sock.RemoteEndPoint); // } // this.dataControl = _controlVLC._CONTROL_SCREEN; // } // else if (str.ToUpper() == "STOPSTREAM") // { // this.dataControl = _controlVLC._CONTROL_STREAM_STOP; // if (StopStreaming != null) // StopStreaming(this, new EventArgs()); // } // else // { // this.dataControl = _controlVLC._CONTROL_FREE; // } // } #endregion Comment this.RunCMD(client, str); client.Sock.Send(getByteText("OK|200|" + str.ToUpper())); client.SetupRecieveCallback(this); } }