public void Connect(IProtocolFactory factory, IPEndPoint peer) { _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _factory = factory; _factory.StartedConnecting(); IAsyncResult result = _socket.BeginConnect(peer, null, null); _reactor.AddResult(result, ConnectCompleted); }
public void AttachStream(IProtocolFactory factory, Stream readStream, Stream writeStream) { factory.StartedConnecting(); Protocol protocol = factory.BuildProtocol(); StreamConnection connection = new StreamConnection(this, protocol); connection.StartConnection(readStream, writeStream, protocol.ReceiveBufferSize); protocol.MakeConnection(connection); }
void BindInternal(IProtocolFactory factory, IPEndPoint local, IPEndPoint remote) { _socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); _factory = factory; _factory.StartedConnecting(); try { _socket.Bind(local); if (remote != null) { _socket.Connect(remote); } } catch (SocketException ex) { _factory.ConnectionFailed(ex); return; } catch (ObjectDisposedException ex) { _factory.ConnectionFailed(ex); return; } Protocol protocol = _factory.BuildProtocol(); SocketConnection connection = new DatagramSocketConnection(_reactor, protocol); connection.StartConnection(_socket, protocol.ReceiveBufferSize); protocol.MakeConnection(connection); }