Exemplo n.º 1
0
 public TcpClientSink(TcpConnection connection, int timeout)
 {
     conn = connection;
     conn.OnResponseRecieved += OnResponseRecieved;
     stacks = new Dictionary<Guid, IClientChannelSinkStack>();
     responseCache = new Dictionary<Guid, Message>();
     requestCache = new Dictionary<IMethodMessage, Message>();
     this.timeout = timeout;
     if(timeout > 0)
     {
         syncTimers = new Dictionary<Guid, Timer>();
         asyncTimers = new Dictionary<Guid, Timer>();
     }
 }
Exemplo n.º 2
0
 private void AddConnection(TcpConnection conn)
 {
     lock(sync)
     {
         conn.OnRequestRecieved += delegate(Message message)
         {
             if(OnRequestRecieved != null)
                 OnRequestRecieved(message);
         };
         connections.Add(conn);
     }
     conn.StartListening();
 }
Exemplo n.º 3
0
        public TcpConnection GetConnection(string host, int port)
        {
            string key = host + ":" + port;
            TcpConnection conn = null;
            lock(sync)
            {
                try
                {
                    conn = hostConnections[key];
                }
                catch(KeyNotFoundException)
                {
                }
                if(conn != null && !conn.IsAlive)
                {
                    conn.Kill();
                    conn = null;
                }

                if(conn == null)
                {
                    TcpClient client;
                    try
                    {
                        client = new TcpClient(host, port);
                    }
                    catch(SocketException e)
                    {
                        throw new RemotingException("TCP error: Unable to connect to the specified host!", e);
                    }
                    conn = new TcpConnection(this, client.Client);
                    hostConnections[key] = conn;
                    AddConnection(conn);
                }
            }
            return conn;
        }
Exemplo n.º 4
0
 public TcpConnection WaitForConnection(TcpListener listener)
 {
     TcpConnection conn = new TcpConnection(this, listener.AcceptSocket());
     AddConnection(conn);
     return conn;
 }
Exemplo n.º 5
0
 public void RemoveConnection(TcpConnection conn)
 {
     lock(sync)
         connections.Remove(conn);
 }
Exemplo n.º 6
0
 private TcpClientSink GetSink(TcpConnection connection)
 {
     try
     {
         return sinkCache[connection];
     }
     catch(KeyNotFoundException)
     {
         TcpClientSink sink = new TcpClientSink(connection, timeout);
         sinkCache[connection] = sink;
         connection.OnDisconnected += conn => {
             sinkCache.Remove(conn);
         };
         return sink;
     }
 }
Exemplo n.º 7
0
 public OutputStream(TcpConnection connection)
 {
     conn = connection;
     ms = new MemoryStream(conn.sendBuffer);
 }
Exemplo n.º 8
0
 public InputStream(TcpConnection connection)
 {
     conn = connection;
     NextChunk();
 }