Esempio n. 1
0
        protected virtual void Closed(SocketConnectionEventArgs e)
        {
            SocketCloseEventHandler handler = OnClose;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Esempio n. 2
0
 private void OnClientClose(object sender, SocketConnectionEventArgs e)
 {
     if (ConnInfo == null)
     {
         return;
     }
     AddLog(Log.Type.LOG_INFO, "PC -> HOST: DisConnect ID: " + e.ID.ToString()
            + ", IP:" + ConnInfo.Client.Ip
            + ", Port:" + ConnInfo.Client.Port.ToString()
            );
 }
Esempio n. 3
0
 /// <summary>
 /// 서버 동작 을 중지 하고 소켓을 닫습니다.
 /// </summary>
 public void Close()
 {
     ThreadRun = false;
     foreach (var client in RemoteClients.ToList())
     {
         client.Value.Close();
         SocketConnectionEventArgs cev = new SocketConnectionEventArgs(this.id);
         Closed(cev);
     }
     if (serverListener != null)
     {
         serverListener.Stop();
         serverListener = null;
     }
 }
Esempio n. 4
0
        public bool Connect(string Ip, int port)
        {
            bool result = false;

            try
            {
                client = new TcpClient(Ip, port);
                if (client != null && client.Connected)
                {
                    ThreadRun = true;
                    nStream   = client.GetStream();
                    //                rStream = new StreamReader(nStream, Encoding.UTF8);     // Get Message
                    //                wStream = new StreamWriter(nStream, Encoding.UTF8);     // Get Message

                    Thread c_thread = new Thread(new ParameterizedThreadStart(ClientThread));
                    if (c_thread != null)
                    {
                        c_thread.Start(client);
                        // 연결 성공 이벤트를 날린다.
                        SocketConnectionEventArgs cev = new SocketConnectionEventArgs(this.id);
                        Connected(cev);
                        result = true;
                    }
                }
            }
            catch (SocketException se)
            {
                SocketErrorEventArgs eev = new SocketErrorEventArgs(this.id, se);
                ErrorOccured(eev);
            }
            catch (Exception err)
            {
                SocketErrorEventArgs eev = new SocketErrorEventArgs(this.id, err);
                ErrorOccured(eev);
            }

            return(result);
        }