Esempio 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>();
     }
 }
Esempio 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();
 }
Esempio 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;
        }
Esempio n. 4
0
 public TcpConnection WaitForConnection(TcpListener listener)
 {
     TcpConnection conn = new TcpConnection(this, listener.AcceptSocket());
     AddConnection(conn);
     return conn;
 }
Esempio n. 5
0
 public void RemoveConnection(TcpConnection conn)
 {
     lock(sync)
         connections.Remove(conn);
 }
 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;
     }
 }
Esempio n. 7
0
 public OutputStream(TcpConnection connection)
 {
     conn = connection;
     ms = new MemoryStream(conn.sendBuffer);
 }
Esempio n. 8
0
 public InputStream(TcpConnection connection)
 {
     conn = connection;
     NextChunk();
 }