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); } }
//データ受信スタート private void StartReceive(System.Net.Sockets.Socket soc) { AsyncStateObject so = new AsyncStateObject(soc); Console.WriteLine("buffer size is {0}", so.ReceiveBuffer.Length); //非同期受信を開始 soc.BeginReceive(so.ReceiveBuffer, 0, so.ReceiveBuffer.Length, System.Net.Sockets.SocketFlags.None, new System.AsyncCallback(this.ReceiveDataCallback), so); }
private void WaitForData(System.Net.Sockets.Socket soc) { try { if(WorkerCallBack == null) WorkerCallBack = new AsyncCallback(OnDataReceived); soc.BeginReceive(dataBuffer, 0, dataBuffer.Length, SocketFlags.None, WorkerCallBack, null); } catch(SocketException se) { if(OnError != null) OnError(se.Message, soc, se.ErrorCode); } }
/// <summary> /// Waits for client data and handles it when recieved /// </summary> /// <param name="soc"></param> /// <param name="clientNumber"></param> /// <param name="verified"></param> public void WaitForData(System.Net.Sockets.Socket soc, int clientNumber, bool verified) { try { if (pfnWorkerCallBack == null) { // Specify the call back function which is to be invoked when there is any write activity by the connected client pfnWorkerCallBack = new AsyncCallback(OnDataReceived); } SocketPacket theSocPkt = new SocketPacket(soc, clientNumber, verified); soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt); } catch (SocketException e) { WriteToLog(Urgency.ERROR, "Socket Exception: " + e); } }
//------------------------------------------------------------------------- //データ受信スタート //------------------------------------------------------------------------- private static void StartReceive(System.Net.Sockets.Socket soc) { AsyncStateObject so = new AsyncStateObject(soc); //非同期受信を開始 soc.BeginReceive(so.ReceiveBuffer, 0, so.ReceiveBuffer.Length, System.Net.Sockets.SocketFlags.None, new System.AsyncCallback(ReceiveDataCallback), so); mTmpBuffer = new byte[0]; }
// Start waiting for data from the client public static void WaitForData(System.Net.Sockets.Socket soc) { try { if (pfnWorkerCallBack == null) { // Specify the call back function which is to be // invoked when there is any write activity by the // connected client pfnWorkerCallBack = new AsyncCallback(OnDataReceived); } SocketPacket theSocPkt = new SocketPacket(); theSocPkt.m_currentSocket = soc; // Start receiving any data written by the connected client // asynchronously soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt); } catch (SocketException se) { Globals.l2net_home.Add_Text("Errror: Wait for data, exception: " + se.Message, Globals.Red, TextType.BOT); } }
public void WaitForData(System.Net.Sockets.Socket soc, object state) { AsyncCallback pfnWorkerCallBack = new AsyncCallback(OnDataReceived); SocketPacket theSocPkt = new SocketPacket(); theSocPkt.state = state; theSocPkt.m_currentSocket = soc; soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt); }
// Start waiting for data from the client public void WaitForData(System.Net.Sockets.Socket soc) { try { if ( pfnWorkerCallBack == null ){ // Specify the call back function which is to be // invoked when there is any write activity by the // connected client pfnWorkerCallBack = new AsyncCallback (OnDataReceived); } SocketPacket theSocPkt = new SocketPacket (); theSocPkt.m_currentSocket = soc; // Start receiving any data written by the connected client // asynchronously soc .BeginReceive (theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt); } catch(SocketException se) { MessageBox.Show (se.Message ); } }
public void EsperarData(System.Net.Sockets.Socket soc) { try { if (pfnWorkerCallBack == null) { // Specify the call back function which is to be // invoked when there is any write activity by the // connected client pfnWorkerCallBack = new AsyncCallback(AlRecibirData); } SocketPacket theSocPkt = new SocketPacket(); theSocPkt.m_currentSocket = soc; //Comienza a recibir la data escrita por el cliente, usando el metodo Asincrono soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt); } catch (SocketException) { } }
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(); } }
// Start waiting for data from the client private void WaitForData(System.Net.Sockets.Socket soc) { try { if (workerCallback == null) { //Callback for data received from the client workerCallback = new AsyncCallback(OnDataReceived); } SocketPacket theSocPkt = new SocketPacket(); theSocPkt.currentSocket = soc; // Start receiving any data written by the connected client // asynchronously soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, workerCallback, theSocPkt); } catch (SocketException se) { MessageBox.Show(se.Message); } }
// ReSharper disable FunctionRecursiveOnAllPaths private async void StartListening(System.Net.Sockets.Socket socket1) // ReSharper restore FunctionRecursiveOnAllPaths { var buffer = new byte[BufferSize]; int bytesRead = 0; try { bytesRead = await Task.Factory.FromAsync( (cb, s) => socket1.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, cb, s), ias => socket1.EndReceive(ias), null); } catch (SocketException ex) { logger.Warn("Error in socket-communication.", ex); InvokeConnectionClosed(); return; } catch (ObjectDisposedException ex) { logger.Warn("Waiting listening socket was closed", ex); InvokeConnectionClosed(); return; } catch (Exception ex) { logger.Warn("Other error in listening socket communication", ex); InvokeConnectionClosed(); return; } if (bytesRead == 0) { // Connection was closed by the remote host InvokeConnectionClosed(); return; } var targetBytes = new byte[bytesRead]; Array.Copy(buffer, 0, targetBytes, 0, bytesRead); await InvokeDataReceived(targetBytes); StartListening(socket1); }
// Start waiting for data from the client private void WaitForData(System.Net.Sockets.Socket soc, int clientNumber) { try { if ( pfnWorkerCallBack == null ) { // Specify the call back function which is to be // invoked when there is any write activity by the // connected client pfnWorkerCallBack = new AsyncCallback (OnDataReceived); } SocketPacket theSocPkt = new SocketPacket (soc, clientNumber); soc.BeginReceive (theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt); } catch(SocketException se) { Console.WriteLine("dpslamServer/WaitForData(" + PortNumber.ToString() + ")/" + se.Message); } }
/// <summary> /// Start waiting for data from the client /// </summary> /// <param name="thisSocket"> /// Socket to wait on /// </param> public void WaitForData( System.Net.Sockets.Socket thisSocket ) { // METHOD : WaitForData try { // TRY if (WorkerCallBack == null) { // Callback not created yet // Specify the call back function which is to be // invoked when there is any write activity by the // connected client WorkerCallBack = new AsyncCallback(OnDataReceived); } // Callback not created yet SocketPacket theSocPkt = new SocketPacket(); theSocPkt.thisSocket = thisSocket; // Start receiving any data written by the connected client // asynchronously thisSocket.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, WorkerCallBack, theSocPkt); } // TRY catch (SocketException) { // CATCH : SocketException ///We kill this one socket, that is probably already in the .Connected=false ///state, but just for fun we .Close it here. Then we call UpdateControls ///which calls CleanUpDeadSockets which will get rid of this. No error message ///will be displayed, but this connection will drop out of the connection list ///at the bottom of the window. thisSocket.Close(); this.UpdateControls(); } // CATCH : SocketException }
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(); } }
/// <summary> /// Waits for data. /// /// This Method Waits for Data to be recieved by telnet, Once it is recieved, it will /// then Begin to recieve this message, This is done by the SocketPacket Class /// </summary> /// <param name="soc">Soc.</param> /// <param name="clientNumber">Client number.</param> public void WaitForData(System.Net.Sockets.Socket soc, int clientNumber) { try { if (pfnWorkerCallBack == null) { pfnWorkerCallBack = new AsyncCallback(OnDataReceived); } SocketPacket theSocPkt = new SocketPacket(soc, clientNumber); soc.BeginReceive(theSocPkt.dataBuffer, 0,theSocPkt.dataBuffer.Length,SocketFlags.None,pfnWorkerCallBack,theSocPkt); } catch (SocketException se) { Console.WriteLine(se.Message); } }
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 }
public void WaitForData(System.Net.Sockets.Socket oSocket) { try { if (oWorkerCallBack == null) oWorkerCallBack = new AsyncCallback(OnReceive); SocketPacket oSocketPacket = new SocketPacket(); oSocketPacket.oSocket = oSocket; // Start Listening for any Data oSocket.BeginReceive(oSocketPacket.bDataBuffer, 0, oSocketPacket.bDataBuffer.Length, SocketFlags.None, oWorkerCallBack, oSocketPacket); } catch (SocketException ex) { System.Diagnostics.Debugger.Log(0, "1", ex.Message); } }
// Start waiting for data from the client public void WaitForData(System.Net.Sockets.Socket soc, int clientNumber) { try { if (pfnWorkerCallBack == null) { // Specify the call back function which is to be // invoked when there is any write activity by the // connected client pfnWorkerCallBack = new AsyncCallback(OnDataReceived); } SocketPacket theSocPkt = new SocketPacket(soc, clientNumber); soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length, SocketFlags.None, pfnWorkerCallBack, theSocPkt); } catch (SocketException se) { WriteLogErorr("Err WaitForData: " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + ":" + se.Message); } }
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); } }