private static void ReceiveCallback(IAsyncResult ar) { try { // Retrieve the state object and the client socket // from the asynchronous state object. StateObjectTradeFeed state = (StateObjectTradeFeed)ar.AsyncState; Socket sockTradeFeed = state.workSocket; // Read data from the remote device. int bytesRead = sockTradeFeed.EndReceive(ar); if (bytesRead <= 0) { GetInstance.ReplyText = "Connection Dropped"; if (sockTradeFeed.Connected) { MemoryManager.onlineSendFeed = false; sockTradeFeed.Shutdown(SocketShutdown.Both); sockTradeFeed.Close(); } // Signal that all bytes have been received. // receiveDone.Set(); } } catch (Exception e) { Console.WriteLine(e.ToString()); } finally { } }
public static void Receive(Socket sockTradeFeed) { try { // Create the state object. StateObjectTradeFeed state = new StateObjectTradeFeed(); state.workSocket = sockTradeFeed; // Begin receiving the data from the remote device. sockTradeFeed.BeginReceive(state.buffer, 0, StateObjectTradeFeed.BufferSize, 0, new AsyncCallback(ReceiveCallback), state); } catch (Exception e) { } }