Exemple #1
0
        private void connectCallback(IAsyncResult ar)
        {
            try
            {
                socket.EndConnect(ar);
            }
            catch
            {
                if (OnConnectFailed != null)
                {
                    OnConnectFailed(this, new EventArgs());
                }
            }

            if (!socket.Connected)
            {
                if (OnConnectFailed != null)
                {
                    OnConnectFailed(this, new EventArgs());
                }
                return;
            }

            if (OnConnected != null)
            {
                OnConnected(this, null);
            }

            IRCStateObject stateObject = new IRCStateObject();

            socket.BeginReceive(stateObject.buffer, 0, IRCStateObject.bufferSize, SocketFlags.None, new AsyncCallback(recieveCallback), stateObject);
        }
Exemple #2
0
        private void connectCallback(IAsyncResult ar)
        {
            try
            {
                socket.EndConnect(ar);
            }
            catch
            {
                if (OnConnectFailed != null)
                    OnConnectFailed(this, new EventArgs());
            }

            if (!socket.Connected)
            {
                if (OnConnectFailed!=null)
                    OnConnectFailed(this, new EventArgs());
                return;
            }

            if (OnConnected!=null)
                OnConnected(this, null);

            IRCStateObject stateObject = new IRCStateObject();
            socket.BeginReceive(stateObject.buffer, 0, IRCStateObject.bufferSize, SocketFlags.None, new AsyncCallback(recieveCallback), stateObject);
        }
Exemple #3
0
        private void recieveCallback(IAsyncResult ar)
        {
            if (socket.Connected)
            {
                int read = 0;
                try
                {
                    read = socket.EndReceive(ar);
                }
                catch
                {
                    Disconnect();
                    if (OnDisconnected != null)
                    {
                        OnDisconnected(this, new EventArgs());
                    }
                }

                IRCStateObject stateObject = (IRCStateObject)ar.AsyncState;

                if (read > 0 || stateObject.lastBuffer != "")
                {
                    string strData = stateObject.lastBuffer + Encoding.Default.GetString(stateObject.buffer, 0, read);

                    strData = strData.Replace("\r\n", "\n").Replace("\r", "\n");

                    while (strData.Length > 0 && strData[0] == '\n')
                    {
                        strData = strData.Substring(1);
                    }

                    //try
                    //{
                    stateObject.lastBuffer = onData(strData);
                    //}
                    //catch (Exception e)
                    //{
                    //	Console.WriteLine("Data could not be parsed:");
                    //	Console.WriteLine(e.Message);
                    //	Console.WriteLine(e.Source);
                    //	Console.WriteLine(e.StackTrace);
                    //}
                }

                if (socket.Connected)
                {
                    try { socket.BeginReceive(stateObject.buffer, 0, IRCStateObject.bufferSize, SocketFlags.None, new AsyncCallback(recieveCallback), stateObject); }
                    catch
                    {
                        if (OnDisconnected != null)
                        {
                            OnDisconnected(this, new EventArgs());
                        }
                    }
                }
                else
                {
                    if (OnDisconnected != null)
                    {
                        OnDisconnected(this, new EventArgs());
                    }
                }
            }
            else
            {
                if (OnDisconnected != null)
                {
                    OnDisconnected(this, new EventArgs());
                }
            }
        }