예제 #1
0
        public void ConnectCallback(System.IAsyncResult ar)
        {
            //prntSome.printSome("ConnectCallback");
            try
            {
                // Get The connection socket from the callback
                System.Net.Sockets.Socket sock1 = (System.Net.Sockets.Socket) ar.AsyncState;

                if (sock1.Connected)
                {
                    uc_CommsStateObject StateObject = new uc_CommsStateObject ();

                    StateObject.Socket = sock1;

                    // Assign Callback function to read from Asyncronous Socket
                    callbackProc = new System.AsyncCallback (OnReceivedData);

                    // Begin reading data asyncronously
                    sock1.BeginReceive (StateObject.Buffer, 0, StateObject.Buffer.Length,
                        System.Net.Sockets.SocketFlags.None, callbackProc, StateObject);
                }
            }

            catch (System.Exception CurException)
            {
                System.Console.WriteLine ("ConnectCallback: " + CurException.Message);
            }
        }
예제 #2
0
        public void ConnectCallback(System.IAsyncResult ar)
        {
            //prntSome.printSome("ConnectCallback");
            try
            {
                // Get The connection socket from the callback
                System.Net.Sockets.Socket sock1 = (System.Net.Sockets.Socket)ar.AsyncState;

                if (sock1.Connected)
                {
                    uc_CommsStateObject StateObject = new uc_CommsStateObject();

                    StateObject.Socket = sock1;

                    // Assign Callback function to read from Asyncronous Socket
                    callbackProc = new System.AsyncCallback(OnReceivedData);

                    // Begin reading data asyncronously
                    sock1.BeginReceive(StateObject.Buffer, 0, StateObject.Buffer.Length,
                                       System.Net.Sockets.SocketFlags.None, callbackProc, StateObject);
                }
            }

            catch (System.Exception CurException)
            {
                System.Console.WriteLine("ConnectCallback: " + CurException.Message);
            }
        }
예제 #3
0
        public void OnReceivedData(System.IAsyncResult ar)
        {
            ////prntSome.printSome("OnReceivedData");
            // Get The connection socket from the callback
            uc_CommsStateObject StateObject = (uc_CommsStateObject)ar.AsyncState;

            // Get The data , if any
            int nBytesRec = StateObject.Socket.EndReceive(ar);

            if (nBytesRec > 0)
            {
                string sReceived = "";
                string sample    = "";
                char   aaachar;

                for (int i = 0; i < nBytesRec; i++)
                {
                    aaachar = System.Convert.ToChar(StateObject.Buffer[i]);
                    sample  = aaachar.ToString();
                    //prntSome.printSome(sample, "OnReceivedData");
                    sReceived += sample;
                }

                /**rdb**/

                //prntSome.printSome(sReceived, "sReceived", countrdb);
                //countrdb++;

                /**end rdb**/


                this.Invoke(this.RxdTextEvent, new System.String[] { System.String.Copy(sReceived) });
                this.Invoke(this.RxdDataLoaded);
                this.Invoke(this.RefreshEvent);

                // Re-Establish the next asyncronous receveived data callback as
                StateObject.Socket.BeginReceive(StateObject.Buffer, 0, StateObject.Buffer.Length,
                                                System.Net.Sockets.SocketFlags.None, new System.AsyncCallback(OnReceivedData), StateObject);

                /**rdb**/

                string tmpstr = "";
                //this.CharGrid
                for (int ii = 0; ii < this.CharGrid.Length; ii++)
                {
                    var str = new string(this.CharGrid[ii]);
                    tmpstr += str + "\n";
                }

                //prntSome.printSome(tmpstr, "chargrid", counttxtscrnrdb);
                //rdbsb1.Clear();
                //rdbsb1.AppendFormat("\n\nchargrid #: " + counttxtscrnrdb);
                //counttxtscrnrdb++;

                //this.Caret.Pos.ToString();
                //prntSome.printSome(this.Caret.Pos.ToString(), "carret_position", countbmprdb);
                //countbmprdb++;
                /**end rdb**/
            }
            else
            {
                this.runOffline = true;
                // If no data was recieved then the connection is probably dead
                System.Console.WriteLine("Disconnected", StateObject.Socket.RemoteEndPoint);
                rdbmsg.AppendLine("Dead....");
                StateObject.Socket.Shutdown(System.Net.Sockets.SocketShutdown.Both);

                StateObject.Socket.Close();
            }
        }