private void ReceiveThread(string sKey) { try { if (D3BSend == null) { return; } DataBuffer DBuffer = D3BSend.Get(sKey); StateObject state = D2Sockets.Get(sKey); if (state == null) { return; } Socket handler = state.workSocket; if (!handler.IsConnected()) { return; } handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state); } catch (Exception e) { string message = e.Message; } }
public void Stop(string key) { StateObject state = D2Sockets.Get(key); Socket handler = state.workSocket; try { handler.BeginDisconnect(false, new AsyncCallback(DisconnectCallback), state); } catch (SocketException se) { ExceptionBuffer.Add(se); } }
public StateObject GetState(string key) { try { if (D2Sockets == null) { return(null); } return(D2Sockets.Get(key)); } catch { return(null); } }
public byte[] GetResidue(string key) { if (D2Sockets == null || !D2Sockets.Contains(key) || key.IsNullOrEmpty()) { return(null); } try { return(D2Sockets.Get(key).residue); } catch { return(null); } }
public bool SetResidue(string key, byte[] residue) { if (D2Sockets == null || !D2Sockets.Contains(key) || key.IsNullOrEmpty()) { return(false); } try { D2Sockets.Get(key).residue = residue; return(true); } catch { return(false); } }
private void SendThread(string sKey) { DataBuffer DBuffer = D3BSend.Get(sKey); Thread ThrdSend = D2TSend.Get(sKey); StateObject state = D2Sockets.Get(sKey); Socket handler = state.workSocket; if (!handler.Connected) { return; } if (DBuffer == null) { return; } if (!DBuffer.IsDataAvalaible) { return; } string sData = DBuffer.Get(false); //Don't increment data, becouse it is not certain at this point, if it will be send if (sData == null) { return; } else if (sData.Length > 1024) { throw new Exception("Exception in Send() method, packet size is to large."); } DBuffer.IndexerIcrement(); sData.Replace(@"\", @"\\"); sData = TcpAsyncCommon.SOM + sData + TcpAsyncCommon.EOM; byte[] baData = Encoding.ASCII.GetBytes(sData); handler.BeginSend(baData, 0, baData.Length, 0, new AsyncCallback(SendCallback), state); }
public void Stop(string key) { StateObject state = D2Sockets.Get(key); try { if (state != null && state.workSocket != null) { Socket handler = state.workSocket; handler.Shutdown(SocketShutdown.Both); handler.Disconnect(true); handler.Close(); handler.Dispose(); } } catch { } finally { if (D2Sockets != null) { D2Sockets.Remove(key); } if (D2TReceive != null) { D2TReceive.Remove(key); } if (D2TSend != null) { D2TSend.Remove(key); } if (D3BReceive != null) { D3BReceive.Remove(key); } if (D3BSend != null) { D3BSend.Remove(key); } } }