Exemplo n.º 1
0
        private void readMessages()
        {
            SocketStateObject state = new SocketStateObject();

            state.m_SocketFd = this.socketFd;
            this.socketFd.BeginReceive(state.m_DataBuf, 0, SocketStateObject.BUF_SIZE, 0, new AsyncCallback(ReceiveCallback), state);
        }
Exemplo n.º 2
0
        private void ReceiveCallback(IAsyncResult ar)
        {
            try
            {
                /* retrieve the SocketStateObject */
                SocketStateObject state = (SocketStateObject)ar.AsyncState;
                //Socket socketFd = state.m_SocketFd;

                /* read data */
                int size = this.socketFd.EndReceive(ar);

                if (size > 0)
                {
                    state.m_StringBuilder.Append(Encoding.ASCII.GetString(state.m_DataBuf, 0, size));
                    //Console.WriteLine(state.m_StringBuilder.ToString());
                    //Console.WriteLine("Otrzymałem jakąś wiadomość");
                    string message = state.m_StringBuilder.ToString();
                    //this.receiveMessage(message);
                    //this.handleAnswers(message);
                    this.parsingReceiveData(message);
                    this.readMessages();
                    /* get the rest of the data */
                    //socketFd.BeginReceive(state.m_DataBuf, 0, SocketStateObject.BUF_SIZE, 0, new AsyncCallback(ReceiveCallback), state);
                }
                else
                {
                    /* all the data has arrived */
                    if (state.m_StringBuilder.Length > 1)
                    {
                        Console.WriteLine("Otrzymałem jakąś wiadomość");
                        string message = state.m_StringBuilder.ToString();
                        //this.receiveMessage(message);
                        this.parsingReceiveData(message);
                        this.readMessages();
                    }

                    Console.WriteLine("Pusta wiadomość");
                }
            }
            catch (Exception exc)
            {
                //MessageBox.Show("Exception:\t\n" + exc.Message.ToString());
                this.login.setThreadedErrorLabel("Check \"Server Info\" and try again!");
                Console.WriteLine("Check \"Server Info\" and try again!");
            }
        }
Exemplo n.º 3
0
 private void readMessages()
 {
     SocketStateObject state = new SocketStateObject();
     state.m_SocketFd = this.socketFd;
     this.socketFd.BeginReceive(state.m_DataBuf, 0, SocketStateObject.BUF_SIZE, 0, new AsyncCallback(ReceiveCallback), state);
 }