private void acceptCallback(IAsyncResult ar) { try { timer.Enabled = false; socket = listenSocket.EndAccept(ar); DccStateObject dso = new DccStateObject(); socket.BeginReceive(dso.Buffer, 0, DccStateObject.BufferSize, SocketFlags.None, new AsyncCallback(receiveCallback), dso); listenSocket.Close(); if (socket.Connected) { Connected(); } else { if (EtablishFailed != null) { EtablishFailed(this, new EventArgs()); } container.Remove(this); } } catch { if (EtablishFailed != null) { EtablishFailed(this, new EventArgs()); } container.Remove(this); } }
private void receiveCallback(IAsyncResult ar) { DccStateObject dso = (DccStateObject)ar.AsyncState; try { int intRead = socket.EndReceive(ar); if (intRead > 0) { OnData(dso.Buffer, intRead); socket.BeginReceive(dso.Buffer, 0, DccStateObject.BufferSize, SocketFlags.None, new AsyncCallback(receiveCallback), dso); } else { CloseSocket(); Disconnected(); container.Remove(this); } } catch { CloseSocket(); Disconnected(); container.Remove(this); } }
private void connectCallback(IAsyncResult ar) { try { socket.EndConnect(ar); } catch { if (EtablishFailed != null) { EtablishFailed(this, new EventArgs()); } return; } if (socket.Connected) { DccStateObject dso = new DccStateObject(); socket.BeginReceive(dso.Buffer, 0, DccStateObject.BufferSize, SocketFlags.None, new AsyncCallback(receiveCallback), dso); Connected(); } else { CloseSocket(); if (EtablishFailed != null) { EtablishFailed(this, new EventArgs()); } container.Remove(this); } }
private void connectCallback(IAsyncResult ar) { try { socket.EndConnect(ar); } catch { if (EtablishFailed != null) EtablishFailed(this, new EventArgs()); return; } if (socket.Connected) { DccStateObject dso = new DccStateObject(); socket.BeginReceive(dso.Buffer, 0, DccStateObject.BufferSize, SocketFlags.None, new AsyncCallback(receiveCallback), dso); Connected(); } else { CloseSocket(); if (EtablishFailed!=null) EtablishFailed(this, new EventArgs()); container.Remove(this); } }
private void acceptCallback(IAsyncResult ar) { try { timer.Enabled = false; socket = listenSocket.EndAccept(ar); DccStateObject dso = new DccStateObject(); socket.BeginReceive(dso.Buffer, 0, DccStateObject.BufferSize, SocketFlags.None, new AsyncCallback(receiveCallback), dso); listenSocket.Close(); if (socket.Connected) Connected(); else { if (EtablishFailed!=null) EtablishFailed(this, new EventArgs()); container.Remove(this); } } catch { if (EtablishFailed!=null) EtablishFailed(this, new EventArgs()); container.Remove(this); } }