/// <summary> /// The Connect method attempts to connect the specified /// session handler to the peer system that is accepting /// connections on the specified endpoint. /// </summary> /// <param name="endpoint"> /// The endpoint of a peer session that the connector is /// to connect the supplied session handler to. /// </param> /// <param name="session"> /// The VFX IPC session handler that is to be connected /// to the peer system at the specified endpoint. /// </param> public void Connect(IPEndPoint endpoint, IVfxIpcSession session) { // REC: Create an instance of a socket that will be // used to connect to the peer system: Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); // REC: Create an instance of the IpcState class that // will provide the context for the asynch request: IpcState ipcState = new IpcState(socket, endpoint, session); // REC: Initiate the asynchronous connection request: ipcState.IpcSocket.BeginConnect(ipcState.IpcEndpoint, HandleConnect, ipcState); }
private void CompleteAccept(IAsyncResult ar) { IoContext context = ar.AsyncState as IoContext; if (context != null) { try { Socket peer = context.IpcSocket.EndAccept(ar); // REC: Locate the factory associated with this endpoint // and create the appropriate type of session instance: if (_mapFactories.ContainsKey(context.IpcEndPoint)) { IPEndPoint peerEP = peer.RemoteEndPoint as IPEndPoint; if (ValidatePeer(peerEP)) { VfxTcpModule tcpModule = new VfxTcpModule(); tcpModule.Init(peer, this.RxBuffering); // REC: Create a new instance of the session handler that // is configured for the endpoint and associated the // client IO stream with it: IVfxIpcSession session = _mapFactories[context.IpcEndPoint].CreateSession(); session.Init(tcpModule); } else { peer.Close(); } } // REC: Initiate another asynchronous connection: context.IpcSocket.BeginAccept(CompleteAccept, context); } catch (System.ObjectDisposedException) { // REC: This exception gets thrown when an asynchronous // accept fails due to the socket it was initiated from // being closed. This is part of the shutdown procedure // and should just be caught and ignored. } } }
/// <summary> /// Initializes a new instance of IpcState with the /// specified parameters. /// </summary> /// <param name="socket"> /// The TCP socket that is associated with the /// asynchronous operation. /// </param> /// <param name="endpoint"> /// The .NET endpoint that is associated with the /// asynchronous operation. /// </param> /// <param name="session"> /// The VFX IPC handler that is associated with the /// asynchronous operation. /// </param> public IpcState(Socket socket, IPEndPoint endpoint, IVfxIpcSession session) { IpcSocket = socket; IpcEndpoint = endpoint; IpcSession = session; }