void OnSocketConnected(Socket socket) { var networkStream = new NetworkStream(socket); queue = new ProcessingQueue(networkStream, new Logger()); queue.OnReceive += messageReceived; queue.Start(); }
private async Task OpenChannel(int port, string hostId) { var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); var namedDependencyProvider = new NamedCacheDependencyProvider(); var contexts = new Dictionary<int, ApplicationContext>(); var services = new ServiceProvider(_services); // This fixes the mono incompatibility but ties it to ipv4 connections var listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); listenSocket.Bind(new IPEndPoint(IPAddress.Loopback, port)); listenSocket.Listen(10); Console.WriteLine("Listening on port {0}", port); for (; ;) { var acceptSocket = await AcceptAsync(listenSocket); Console.WriteLine("Client accepted {0}", acceptSocket.LocalEndPoint); var stream = new NetworkStream(acceptSocket); var queue = new ProcessingQueue(stream); var connection = new ConnectionContext( contexts, services, cache, cacheContextAccessor, namedDependencyProvider, queue, hostId); queue.OnReceive += message => { // Enumerates all project contexts and return them to the // sender if (message.MessageType == "EnumerateProjectContexts") { WriteProjectContexts(message, queue, contexts); } else { // Otherwise it's a context specific message connection.OnReceive(message); } }; queue.Start(); } }