void StartConnectingSocket(IPAddress addr, int port) { socket = new System.Net.Sockets.Socket(addr.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try { socket.BeginConnect(addr, port, (ar) => { try { socket.EndConnect(ar); loop.NonBlockInvoke(connectedCallback); } catch { } }, null); } catch { } }
private void StartConnectingSocket(IPAddress addr, int port) { StartTimeout(); socket = new Socket(addr.AddressFamily, SocketType.Stream, ProtocolType.Tcp); try { socket.BeginConnect(addr, port, (ar) => { try { socket.EndConnect(ar); if (Connected != null) { loop.NonBlockInvoke(delegate { Connected(this); }); } } catch { OnError(); } }, null); } catch { OnError(); } }
void OnReadDone(IAsyncResult ar) { int result = stream.EndRead(ar); if (result > 0) { loop.NonBlockInvoke(delegate { RaiseData(new ByteBuffer(readBuffer, 0, result)); ReadNextBuffer(); }); } else { loop.NonBlockInvoke(delegate { PauseReading(); RaiseEndOfStream(); }); } }