コード例 #1
0
ファイル: Client.cs プロジェクト: morz/OETS.Journal
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         // dispose managed resources
         if (sSocket != null)
         {
             sSocket.Dispose();
             sSocket = null;
         }
     }
 }
コード例 #2
0
ファイル: ClientManager.cs プロジェクト: morz/OETS.Journal
        /// <summary>
        /// A ClientManager is responsible for managing a connection from a client.
        /// For each client connected there will be one separate ClientManager object.
        /// The socket used by the ClientManager uses asynchronous call to Receive and 
        /// send data.
        /// </summary>
        public ClientManager(ref Socket clientSocket)
        {
            if (clientSocket == null)
                throw new Exception("Client socket is not initialized!");

            // the endpoint stores information from the client side
            socket = clientSocket;
            endPoint = (IPEndPoint)socket.RemoteEndPoint;

            SockUtils.SetKeepAlive(socket, 600 * 1000, 60 * 1000);

            sSocket = new SSocket(ref socket);
            sSocket.Received += new EventHandler(OnChatSocketReceived);
            sSocket.Disconnected += new EventHandler(OnChatSocketDisconnected);            
            sSocket.Receive();

            m_PingTimer = new System.Threading.Timer(m_PingTimerCallback);
        }
コード例 #3
0
ファイル: Client.cs プロジェクト: morz/OETS.Journal
        /// <summary>
        /// Disconnect from the server.
        /// Events fired:
        ///     Disconnected
        /// </summary>
        public void Disconnect()
        {
            if (sSocket != null)
            {
                sSocket.Received -= new EventHandler(OnChatSocketReceived);
                sSocket.Disconnected -= new EventHandler(OnChatSocketDisconnected);

                sSocket.Close();
                sSocket.Dispose();
                sSocket = null;
            }

            Trace.WriteLine("[OETS.Client] Disconnect");

            if (Disconnected != null)
                Disconnected(this, new TimedEventArgs());
        }
コード例 #4
0
ファイル: Client.cs プロジェクト: morz/OETS.Journal
        private void OnChatSocketReceived(object sender, EventArgs e)
        {
            SSocket cs = sender as SSocket;

            if (cs == null)
                return;

            if (CommandReceived != null)
            {
                SSocket chatSocketCopy = new SSocket(cs);
                CommandReceived(this, new SSEventArgs(chatSocketCopy));
            }

            switch (cs.Command)
            {
                case OpcoDes.SMSG_SERVER_DISCONNECTED:
                    Disconnect();
                    if (ServerDisconnected != null)
                        ServerDisconnected(this, new TimedEventArgs());
                    break;

                default:
                    //sSocket.Receive();
                    break;
            }
        }
コード例 #5
0
ファイル: Client.cs プロジェクト: morz/OETS.Journal
        /// <summary>
        /// Ends the pending connection request to the server and requests login.
        /// </summary>
        private void OnConnect(IAsyncResult ar)
        {
            try
            {
                Socket socket = (Socket)ar.AsyncState;
                socket.EndConnect(ar);                
                // send keep alive after 10 minute of inactivity
                SockUtils.SetKeepAlive(socket, 600 * 1000, 60 * 1000);  

                // the socket was connected, create the ChatSocket used for communication
                this.sSocket = new SSocket(ref socket);
                this.sSocket.Received += new EventHandler(OnChatSocketReceived);
                this.sSocket.Disconnected += new EventHandler(OnChatSocketDisconnected);

                // set the connected time
                this.dtConnectedOn = DateTime.Now;

                // fire the Connected event
                if (Connected != null)
                    Connected(this, new TimedEventArgs());                

                sSocket.Receive();

                SendRequestLogin();
            }
            catch (Exception exc)
            {
                if (ConnectFailed != null)
                    ConnectFailed(this, new TimedEventArgs());

                if (!SockUtils.HandleSocketError(exc))
                    throw exc;
            }
        }
コード例 #6
0
ファイル: Client.cs プロジェクト: morz/OETS.Journal
        private void ProcessConnect(SocketAsyncEventArgs args)
        {
            try
            {
                Socket socket = args.AcceptSocket;
                if (socket == null || !socket.Connected)
                {
                    if (ConnectFailed != null)
                        ConnectFailed(this, new TimedEventArgs());
                    return;
                }

                // send keep alive after 10 minute of inactivity
                SockUtils.SetKeepAlive(socket, 600 * 1000, 60 * 1000);

                // the socket was connected, create the ChatSocket used for communication
                this.sSocket = new SSocket(ref socket);
                this.sSocket.Received += new EventHandler(OnChatSocketReceived);
                this.sSocket.Disconnected += new EventHandler(OnChatSocketDisconnected);

                // set the connected time
                this.dtConnectedOn = DateTime.Now;

                // fire the Connected event
                if (Connected != null)
                    Connected(this, new TimedEventArgs());

                sSocket.Receive();

                SendRequestLogin();
            }
            catch
            {
                if (ConnectFailed != null)
                    ConnectFailed(this, new TimedEventArgs());
            }
        }
コード例 #7
0
ファイル: SSocket.cs プロジェクト: morz/OETS.Journal
 /// <summary>
 /// Deep clone of a ChatSocket object without the network stream cloned.
 /// It is used when a new ChatSocket object is passed on to methods, events that 
 /// do not need a network stream.
 /// </summary>
 public SSocket(SSocket cp) 
 {
     this.target = cp.Target;
     this.command = cp.Command;
     this.metatype = cp.Metatype;
     this.metadata = cp.Metadata;
     this.sentBytes = cp.SentBytes;
     this.receivedBytes = cp.ReceivedBytes;
 }
コード例 #8
0
ファイル: SSEventArgs.cs プロジェクト: morz/OETS.Journal
 public SSEventArgs(SSocket SSocket)
     : base()
 {
     this.sSocket = SSocket;
 }