예제 #1
0
        private void WaitForData(Socket soc)
        {
            try
            {
                if (pfnWorkerCallBack == null)
                {
                    pfnWorkerCallBack = new AsyncCallback(OnDataReceived);
                }
                CSocketPacket theSocPkt = new CSocketPacket(BufferLength);
                theSocPkt.thisSocket = soc;
                // now start to listen for any data...
                soc.BeginReceive(
                    theSocPkt.dataBuffer,
                    0,
                    theSocPkt.dataBuffer.Length,
                    SocketFlags.None,
                    pfnWorkerCallBack,
                    theSocPkt);
            }
            catch (SocketException sex)
            {
                Debug.Fail(sex.ToString(), "WaitForData: Socket failed");
            }

        }
 public void WaitForData(System.Net.Sockets.Socket soc)
 {
     try
     {
         if (pfnWorkerCallBackPlayer2 == null)
         {
             pfnWorkerCallBackPlayer2 = new AsyncCallback(OnDataReceived);
         }
         CSocketPacket theSocPkt = new CSocketPacket();
         theSocPkt.thisSocket = soc;
         soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBackPlayer2, theSocPkt);
     }
     catch (Exception se)
     {
         MessageBox.Show(se.Message);
     }
 }
예제 #3
0
 public void WaitForData(Socket worker)
 {
     try
     {
         if (workercallback == null)
         {
             workercallback = new AsyncCallback(OnDataReceived);
         }
         CSocketPacket csocket = new CSocketPacket();
         csocket.thisSocket = worker;
         worker.BeginReceive(csocket.dataBuffer, 0, csocket.dataBuffer.Length, SocketFlags.None, workercallback, csocket);
     }
     catch (SocketException se)
     {
         Console.WriteLine(se);
     }
 }
        private void OnDataReceived(IAsyncResult asyn)
        {
            CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState;
            Socket        socket    = theSockId.thisSocket;

            if (!socket.Connected)
            {
                return;
            }

            try
            {
                int iRx;
                try
                {
                    iRx = socket.EndReceive(asyn);
                }
                catch (SocketException)
                {
                    Debug.Write("Apperently client has been closed and connot answer.");

                    OnConnectionDroped(socket);
                    return;
                }

                if (iRx == 0)
                {
                    Debug.Write("Apperently client socket has been closed.");
                    // If client socket has been closed (but client still answers)-
                    // EndReceive will return 0.
                    OnConnectionDroped(socket);
                    return;
                }

                byte[] bytes = theSockId.dataBuffer;

                RaiseMessageRecived(bytes);

                WaitForData(m_socWorker);
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString(), "OnClientConnection: Socket failed");
            }
        }
예제 #5
0
 private void WaitForDataServerRx(System.Net.Sockets.Socket soc)
 {
     try
     {
         if (pfnWorkerCallBack == null)
         {
             pfnWorkerCallBack = new AsyncCallback(OnDataReceivedServer);
         }
         CSocketPacket theSocPkt = new CSocketPacket();
         theSocPkt.thisSocket = soc;
         // now start to listen for any data...
         soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt);
     }
     catch (Exception se)
     {
         CallErrorHandler(se.Message);
     }
 }
예제 #6
0
 public void WaitForData()
 {
     try
     {
         if (pfnCallBack == null)
         {
             pfnCallBack = new AsyncCallback(OnDataReceived);
         }
         CSocketPacket theSocPkt = new CSocketPacket();
         theSocPkt.thisSocket = m_socClient;
         // now start to listen for any data...
         m_asynResult = m_socClient.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnCallBack, theSocPkt);
     }
     catch (SocketException se)
     {
         MessageBox.Show(se.Message);
     }
 }
예제 #7
0
 public void WaitForData(System.Net.Sockets.Socket soc)
 {
     try
     {
         if (pfnWorkerCallBack == null)
         {
             pfnWorkerCallBack = new AsyncCallback(OnDataReceived);
         }
         CSocketPacket theSocPkt = new CSocketPacket();
         theSocPkt.thisSocket = soc;
         // now start to listen for any data...
         soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt);
     }
     catch (SocketException se)
     {
         Console.WriteLine(se.Message);
     }
 }
예제 #8
0
 public void WaitForData(Socket soc, int len)
 {
     try
     {
         if (pfnWorkerCallBack == null)
         {
             pfnWorkerCallBack = new AsyncCallback(OnDataReceived);
         }
         CSocketPacket theSocPkt = new CSocketPacket();
         theSocPkt.dataBuffer = new byte[len];
         theSocPkt.thisSocket = soc;
         // now start to listen for any data...
         soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt);
     }
     catch (SocketException se)
     {
         Console.WriteLine(se.Message);
     }
 }
예제 #9
0
 public void WaitForData(System.Net.Sockets.Socket soc)
 {
     try
     {
         if (pfnWorkerCallBack == null)
         {
             pfnWorkerCallBack = new AsyncCallback(OnDataReceived);
         }
         CSocketPacket theSocPkt = new CSocketPacket();
         theSocPkt.thisSocket = soc;
         // now start to listen for any data...
         soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt);
     }
     catch (SocketException se)
     {
         System.Diagnostics.Debugger.Log(0, "1", "\n " + se.Message + "\n");
         ClientDisconnect();
     }
 }
예제 #10
0
 public void OnDataReceived2(IAsyncResult asyn)
 {
     try
     {
         CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState;
         int           iRx       = 0;
         iRx = theSockId.thisSocket.EndReceive(asyn);
         char[] chars          = new char[iRx + 1];
         System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
         int           charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
         System.String szData  = new System.String(chars);
         //gauti pranesimus
         WaitForData2(socWorkerP2toD);
     }
     catch (Exception se)
     {
         MessageBox.Show(se.Message);
     }
 }
예제 #11
0
        private void WaitForData(System.Net.Sockets.Socket soc)
        {
            try
            {
                if (pfnWorkerCallBack == null)
                {
                    pfnWorkerCallBack = new AsyncCallback(OnDataReceived);
                }

                CSocketPacket theSocPkt = new CSocketPacket(BufferLength);
                theSocPkt.thisSocket = soc;

                // now start to listen for any data...
                soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt);
            }
            catch (SocketException sex)
            {
                Debug.Fail(sex.ToString(), "WaitForData: Socket failed");
            }
        }
예제 #12
0
 /// <summary>
 /// 클라이언트로 부터 데이터 전송을 기다린다
 /// </summary>
 /// <param name="soc"></param>
 public void WaitForData(System.Net.Sockets.Socket soc)
 {
     try
     {
         if (pfnWorkerCallBack == null)
         {
             pfnWorkerCallBack = new AsyncCallback(OnDataReceived);
         }
         CSocketPacket theSocPkt = new CSocketPacket();
         theSocPkt.thisSocket = soc;
         // now start to listen for any data...
         soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt);
     }
     catch (SocketException ex)
     {
         throw new Exception(ex.Message, ex);
     }
     catch
     {
         throw;
     }
 }
예제 #13
0
 /// <summary>
 /// Establishes an Async Callback Procedure that receives data being sent via the IRTrans Server.
 /// </summary>
 private void WaitForData()
 {
     try
     {
         if (pfnCallBack == null)
         {
             pfnCallBack = new AsyncCallback(OnDataReceived);
         }
         CSocketPacket socketPkt = new CSocketPacket();
         socketPkt.thisSocket = m_Socket;
         // Now start to listen for any data.
         m_asynResult = m_Socket.BeginReceive(socketPkt.receiveBuffer, 0, socketPkt.receiveBuffer.Length,
                                              SocketFlags.None, pfnCallBack, socketPkt);
     }
     catch (SocketException se)
     {
         if (logVerbose)
         {
             Log.Info("IRTrans: Error on receive from socket: {0}", se.Message);
         }
     }
 }
 public void OnDataReceived(IAsyncResult asyn)
 {
     try
     {
         CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState;
         int           iRx       = 0;
         iRx = theSockId.thisSocket.EndReceive(asyn);
         char[] chars          = new char[iRx + 1];
         System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
         int           charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
         System.String szData  = new System.String(chars);
         //gauti pranesimus
         //gaunama korta
         if (szData.Substring(0, 1) == "a")
         {
             kortuP1rankoje++;
             MessageBox.Show(System.Convert.ToString(kortuP1rankoje));
             korta nauja = new korta();
             nauja.rusis = szData.Substring(1, 1);
             if (szData.Substring(2, 1) == "1")
             {
                 nauja.skaicius = System.Convert.ToInt16(szData.Substring(2, 2));
             }
             else
             {
                 nauja.skaicius = System.Convert.ToInt16(szData.Substring(2, 1));
             }
             kortos[kortuP1rankoje] = nauja;
             atvaizduoti();
         }
         //
         //
         WaitForData(socToDesk);
     }
     catch (Exception se)
     {
         MessageBox.Show(se.Message);
     }
 }
예제 #15
0
 public void OnDataReceived(IAsyncResult asyn)
 {
     try
     {
         CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState;
         //end receive...
         int iRx = 0;
         iRx = theSockId.thisSocket.EndReceive(asyn);
         char[] chars          = new char[iRx + 1];
         System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
         int           charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
         System.String szData  = new System.String(chars);
         txtDataRx.Text = txtDataRx.Text + szData;
         WaitForData();
     }
     catch (ObjectDisposedException)
     {
         System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n");
     }
     catch (SocketException se)
     {
         MessageBox.Show(se.Message);
     }
 }
예제 #16
0
 public void OnDataReceived(IAsyncResult asyn)
 {
     try
     {
         CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState;
         //end receive...
         int iRx = 0;
         iRx = theSockId.thisSocket.EndReceive(asyn);
         char[] chars          = new char[iRx + 1];
         System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
         int           charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
         System.String szData  = new System.String(chars);
         parseData(szData);
         WaitForData(m_socWorker[m_clientCount]);
     }
     catch (ObjectDisposedException)
     {
         cb.SetText("OnDataReceived: Socket has been closed");
     }
     catch (SocketException se)
     {
         cb.SetText(se.Message);
     }
 }
예제 #17
0
        static void OnDataReceived(IAsyncResult asyn)
        {
            try
            {
                CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState;
                //end receive...
                int iRx = 0;
                iRx = theSockId.thisSocket.EndReceive(asyn);
                char[] chars          = new char[iRx];
                System.Text.Decoder d = System.Text.Encoding.Default.GetDecoder();
                int           charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
                System.String message = ((new System.String(chars)).Trim()); //.ToLower();


                if (iRx > 0)
                {
                    //System.String message = enc.GetString(theSockId.dataBuffer);
                    //System.String message = new System.String(theSockId.dataBuffer, 0, iRx);

                    // Console.WriteLine("Received and trimmend:" + message);

                    string[] tokenList = message.Split('#');

                    foreach (string token in tokenList)
                    {
                        // Console.WriteLine("Speech Processor: act token =" + token);

                        if (String.Compare(token, "@close@") == 0)
                        {
                            Console.WriteLine("Speech Processor: received CLOSE");
                            completed = true;
                        }
                        else if (String.Compare(token, "@stop@") == 0)
                        {
                            Console.WriteLine("Speech Processor: received STOP, cleaning up Recognizer !");
                            recognizer.UnloadAllGrammars();
                            recognizer.RequestRecognizerUpdate();
                            recognizer.Dispose();

                            recognizer = null;
                            tts        = null;
                        }
                        else if (token.StartsWith("say:"))
                        {
                            Console.WriteLine("Speech Processor: saying:" + token.Substring(4, token.Length - 4));
                            Speak(token.Substring(4, token.Length - 4));
                        }
                        else if (token.StartsWith("culture:"))
                        {
                            string newCulture = (token.Substring(8, token.Length - 8));
                            Console.WriteLine("Speech Processor: Initialising Engines for new culture:" + newCulture);
                            strCulture = newCulture;
                            CreateSynthesizer();
                            CreateRecognizer();
                        }
                        else if (token.StartsWith("ttsonly:"))
                        {
                            string newCulture = (token.Substring(8, token.Length - 8));
                            Console.WriteLine("Speech Processor: Initialising TTS-Engine for new culture:" + newCulture);
                            strCulture = newCulture;
                            CreateSynthesizer();
                        }
                        else if (token.StartsWith("grammar:"))
                        {
                            string[] words = (token.Substring(8, token.Length - 8)).Split(';');

                            if (recognizer != null)
                            {
                                UpdateGrammar(words);

                                Console.WriteLine("Speech Processor: Starting asynchronous recognition ...");
                                try
                                {
                                    recognizer.RecognizeAsync(RecognizeMode.Multiple);
                                    SocketSend("@SpeechProcessor OK@");
                                }
                                catch (Exception ex)
                                { Console.WriteLine("Speech Processor: could not start asynchronous recognition ..."); }
                            }
                            else
                            {
                                Console.WriteLine("Speech Processor: could not start asynchronous recognition due to missing recognizer.");
                            }
                        }
                        else if (token.StartsWith("confidence:"))
                        {
                            confidenceLevel = double.Parse(token.Substring(11, token.Length - 11), System.Globalization.CultureInfo.InvariantCulture);
                            //Console.WriteLine("confidence update:" + token.Substring(11, token.Length - 11));
                            Console.WriteLine("Speech Processor: confidence update:" + confidenceLevel);
                        }
                        else if (token.StartsWith("speechLoopDelay:"))
                        {
                            speechLoopDelay = int.Parse(token.Substring(16, token.Length - 16), System.Globalization.CultureInfo.InvariantCulture);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Speech Processor: received empty message, closing down socket !"); completed = true;
                }

                if (!completed)
                {
                    WaitForData();
                }
            }
            catch (ObjectDisposedException)
            {
                Console.WriteLine("Speech Processor: OnDataReceived: Socket has been closed");
            }
            catch (SocketException se)
            {
                Console.WriteLine(se.Message);
            }
        }
예제 #18
0
 /// <summary>
 /// Establishes an Async Callback Procedure that receives data being sent via the IRTrans Server.
 /// </summary>
 private void WaitForData()
 {
   try
   {
     if (pfnCallBack == null)
     {
       pfnCallBack = new AsyncCallback(OnDataReceived);
     }
     CSocketPacket socketPkt = new CSocketPacket();
     socketPkt.thisSocket = m_Socket;
     // Now start to listen for any data.
     m_asynResult = m_Socket.BeginReceive(socketPkt.receiveBuffer, 0, socketPkt.receiveBuffer.Length,
                                          SocketFlags.None, pfnCallBack, socketPkt);
   }
   catch (SocketException se)
   {
     if (logVerbose)
     {
       Log.Info("IRTrans: Error on receive from socket: {0}", se.Message);
     }
   }
 }
예제 #19
0
        /// <summary>
        /// reads the incomming data and triggers the DataReceived event when done
        /// </summary>
        private void Read(IAsyncResult ar)
        {
            CSocketPacket theSockId          = (CSocketPacket)ar.AsyncState;
            Socket        socket             = theSockId.thisSocket;
            int           sizeOfReceivedData = ConnectionSocket.EndReceive(ar);

            if (sizeOfReceivedData > 0)
            {
                int start = 0, end = dataBuffer.Length - 1;

                // if we are not already reading something, look for the start byte as specified in the protocol
                if (!readingData)
                {
                    for (start = 0; start < dataBuffer.Length - 1; start++)
                    {
                        if (dataBuffer[start] == (byte)WrapperBytes.Start)
                        {
                            readingData = true;                  // we found the begining and can now start reading
                            start++;                             // we dont need the start byte. Incrementing the start counter will walk us past it
                            break;
                        }
                    }
                }                 // no else here, the value of readingData might have changed

                // if a begining was found in the buffer, or if we are continuing from another buffer
                if (readingData)
                {
                    bool endIsInThisBuffer = false;
                    // look for the end byte in the received data
                    for (end = start; end < sizeOfReceivedData; end++)
                    {
                        byte currentByte = dataBuffer[end];
                        if (dataBuffer[end] == (byte)WrapperBytes.End)
                        {
                            endIsInThisBuffer = true;                             // we found the ending byte
                            break;
                        }
                    }

                    // the end is in this buffer, which means that we are done reading
                    if (endIsInThisBuffer)
                    {
                        // we are no longer reading data
                        readingData = false;
                        // put the data into the string builder
                        dataString.Append(Encoding.UTF8.GetString(dataBuffer, start, end - start));
                        // trigger the event
                        int size = Encoding.UTF8.GetBytes(dataString.ToString().ToCharArray()).Length;
                        OnDataReceived(new DataReceivedEventArgs(size, dataString.ToString()));
                        dataString = null;
                        dataString = new StringBuilder();
                    }
                    else                     // if the end is not in this buffer then put everyting from start to the end of the buffer into the datastring and keep on reading
                    {
                        dataString.Append(Encoding.UTF8.GetString(dataBuffer, start, end - start));
                    }
                }

                // continue listening for more data
                Listen();
            }
            else             // the socket is closed
            {
                if (Disconnected != null)
                {
                    Disconnected(this, EventArgs.Empty);
                }
            }
        }
예제 #20
0
		private void WaitForDataServerRx(System.Net.Sockets.Socket soc)
		{
			try
			{
				if  ( pfnWorkerCallBack == null ) 
				{
					pfnWorkerCallBack = new AsyncCallback (OnDataReceivedServer);
				}
				CSocketPacket theSocPkt = new CSocketPacket ();
				theSocPkt.thisSocket = soc;
				// now start to listen for any data...
				soc .BeginReceive (theSocPkt.dataBuffer ,0,theSocPkt.dataBuffer.Length ,SocketFlags.None,pfnWorkerCallBack,theSocPkt);
			}
			catch(Exception se)
			{
				CallErrorHandler(se.Message);
			}
		}
예제 #21
0
        /// <summary>
        /// Method is called, whenever a IR Comand is received via the IRTrans Server connection.
        /// </summary>
        /// <param name="asyn"></param>
        private void OnDataReceived(IAsyncResult asyn)
        {
            try
            {
                CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState;
                //Do an end receive first
                int bytesReceived = 0;
                bytesReceived = theSockId.thisSocket.EndReceive(asyn);
                // Map the received data to the structure
                IntPtr ptrReceive = Marshal.AllocHGlobal(bytesReceived);
                Marshal.Copy(theSockId.receiveBuffer, 0, ptrReceive, bytesReceived);
                NETWORKRECV netrecv = (NETWORKRECV)Marshal.PtrToStructure(ptrReceive, typeof(NETWORKRECV));
                if (logVerbose)
                {
                    Log.Info("IRTrans: Command Start --------------------------------------------");
                    Log.Info("IRTrans: Client       = {0}", netrecv.clientid);
                    Log.Info("IRTrans: Status       = {0}", (IrTransStatus)netrecv.statustype);
                    Log.Info("IRTrans: Remote       = {0}", netrecv.remote);
                    Log.Info("IRTrans: Command Num. = {0}", netrecv.command_num.ToString());
                    Log.Info("IRTrans: Command      = {0}", netrecv.command);
                    Log.Info("IRTrans: Data         = {0}", netrecv.data);
                    Log.Info("IRTrans: Command End ----------------------------------------------");
                }

                // Do an action only on Receive and if the command came from the selected Remote
                if ((IrTransStatus)netrecv.statustype == IrTransStatus.STATUS_RECEIVE)
                {
                    if (netrecv.remote.Trim() == remoteModel)
                    {
                        try
                        {
                            if (irtransHandler.MapAction(netrecv.command.Trim()))
                            {
                                if (logVerbose)
                                {
                                    Log.Info("IRTrans: Action mapped");
                                }
                            }
                            else
                            {
                                if (logVerbose)
                                {
                                    Log.Info("IRTrans: Action not mapped");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (logVerbose)
                            {
                                Log.Info("IRTrans: Exception in IRTranshandler: {0}", ex.Message);
                            }
                        }
                    }
                }

                Marshal.FreeHGlobal(ptrReceive);
                WaitForData();
            }
            catch (ObjectDisposedException) {}
            catch (SocketException se)
            {
                if (logVerbose)
                {
                    Log.Info("IRTrans: Error on receive from socket: {0}", se.Message);
                }
            }
        }
예제 #22
0
        /// <summary>
        /// Listens for incomming data
        /// </summary>
        private void Listen()
        {
            CSocketPacket theSocPkt = new CSocketPacket(1000);

            ConnectionSocket.BeginReceive(dataBuffer, 0, dataBuffer.Length, 0, Read, theSocPkt);
        }
예제 #23
0
        /// <summary>
        /// 클라이언트로 부터 데이터 수신시 발생 한다.
        /// </summary>
        /// <param name="asyn"></param>
        public void OnDataReceived(IAsyncResult asyn)
        {
            CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState;

            int ErrorCnt = 0;

            try
            {
                //end receive...
                int iRx = 0;

                if (!theSockId.thisSocket.Connected)
                {
                    theSockId.thisSocket.Close();
                    return;
                }

                Thread.Sleep(50);
                iRx = theSockId.thisSocket.EndReceive(asyn);

                /*
                 * char[] chars = new char[iRx + 1];
                 * System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
                 * int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
                 * System.String szData = new System.String(chars);
                 */

                if (iRx != 0)
                {
                    byte[] byt = new byte[iRx];

                    Array.Copy(theSockId.dataBuffer, 0, byt, 0, iRx);
                    theSockId.dataBuffer = byt;

                    //데이터 수신처리..
                    ThreadPool.QueueUserWorkItem(thCilentSend, theSockId);
                }


                ErrorCnt = 0;

                WaitForData(theSockId.thisSocket);
            }
            catch (ObjectDisposedException)
            {
                System.Diagnostics.Debugger.Log(0, "1", "\nOnDataReceived: Socket has been closed\n");
            }
            catch (SocketException)
            {
                ErrorCnt++;
                //throw new Exception(ex.Message, ex);
                if (ErrorCnt < 50 && theSockId.thisSocket.Connected)
                {
                    WaitForData(theSockId.thisSocket);
                }
            }
            catch
            {
                ErrorCnt++;
                if (ErrorCnt < 50 && theSockId.thisSocket.Connected)
                {
                    WaitForData(theSockId.thisSocket);
                }
            }
        }
예제 #24
0
 private void WaitForData(Socket socWorker)
 {
     try
     {
         if (pfnWorkerCallBack == null)
         {
             pfnWorkerCallBack = new AsyncCallback(OnDataReceived);
         }
         CSocketPacket theSocPkt = new CSocketPacket();
         theSocPkt.thisSocket = socWorker;
         socWorker.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
예제 #25
0
        public void WaitForData(System.Net.Sockets.Socket soc)
        {
            try
            {
                if (pfnWorkerCallBack == null)
                {
                    pfnWorkerCallBack = new AsyncCallback(onDataReceived);
                }
                CSocketPacket theSocPkt = new CSocketPacket();
                theSocPkt.workSocket = soc;
                // now start to listen for any data...
                soc.BeginReceive(theSocPkt.buffer, 0, CSocketPacket.BufferSize, SocketFlags.None, pfnWorkerCallBack, theSocPkt);
            }
            catch (ObjectDisposedException ode)
            {
                m_socketLog.log(LogTools.getExceptionString("ViaStdProto", "WaitForData", ode, "Could not begin receiving on socket: Socket has been closed"));

                m_status = Status.NotConnected;
                soc.Close();
            }
            catch (SocketException se)
            {
                m_socketLog.log(LogTools.getExceptionString("ViaStdProto", "WaitForData", se, "Socket has been closed"));
                m_status = Status.NotConnected;
                soc.Close();
                throw (se);
            }
            // TODO, can throw ArgumentOutOfRangeException also
        }
예제 #26
0
 static void WaitForData()
 {
     try
     {
         if (pfnCallBack == null)
         {
             pfnCallBack = new AsyncCallback(OnDataReceived);
         }
         CSocketPacket theSocPkt = new CSocketPacket();
         theSocPkt.thisSocket = m_socClient;
         // now start to listen for any data...
         m_asynResult = m_socClient.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnCallBack, theSocPkt);
     }
     catch (SocketException se)
     {
         Console.WriteLine(se.Message);
     }
 }
예제 #27
0
        public void WaitForData(System.Net.Sockets.Socket soc)
        {
            try
            {
                if (pfnWorkerCallBack == null)
                {
                    pfnWorkerCallBack = new AsyncCallback(OnDataReceived);
                }
                CSocketPacket theSocPkt = new CSocketPacket();
                theSocPkt.thisSocket = soc;
                // now start to listen for any data...
                soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt);
            }
            catch (SocketException se)
            {
                if (global._net_socket_debug == true) MessageBox.Show(se.Message);
                StopListening();
            }

        }
 public void WaitForData(System.Net.Sockets.Socket soc)
 {
     try
     {
         if (pfnWorkerCallBack == null)
         {
             pfnWorkerCallBack = new AsyncCallback(OnDataReceived);
         }
         CSocketPacket theSocPkt = new CSocketPacket();
         theSocPkt.thisSocket = soc;
         // now start to listen for any data...
         soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt);
     }
     catch (SocketException se)
     {
         System.Diagnostics.Debugger.Log(0, "1", "\n " + se.Message + "\n");
         ClientDisconnect();
     }
 }