Пример #1
0
 // I think host and port will get combined with "resource" as an RCSymbolScalar here.
 public TcpHttpClient(long handle, RCSymbolScalar hostandport)
 {
     _handle = handle;
     _host   = (string)hostandport.Part(1);
     _port   = (long)hostandport.Part(2);
     // _uri = new Uri("http://" + _host + ":" + _port.ToString ());
     _inbox  = new TcpReceiveBox();
     _client = new WebClient();
     _client.UploadDataCompleted   += UploadDataCompleted;
     _client.DownloadDataCompleted += DownloadDataCompleted;
 }
Пример #2
0
 public TcpClient(long handle, RCSymbolScalar symbol, Tcp.Protocol protocol, int timeout)
 {
     _protocol     = protocol;
     _handle       = handle;
     _host         = (string)symbol.Part(1);
     _port         = (long)symbol.Part(2);
     _inbox        = new TcpReceiveBox();
     _outbox       = new TcpOutBox();
     _buffer       = new TcpMessageBuffer();
     _timeout      = timeout;
     _timeoutTimer = null;
 }
Пример #3
0
        public void EvalOpen(RCRunner runner, RCClosure closure, RCLong left, RCSymbol right)
        {
            // Implementing multiple would require some annoying scatter gather logic.
            // Plus what if one fails out of the list?
            if (right.Count != 1)
            {
                throw new Exception("open takes exactly one protocol,host,[port]");
            }
            if (left.Count != 1)
            {
                throw new Exception("open takes a single timeout value");
            }

            RCSymbolScalar symbol   = right[0];
            string         protocol = (string)symbol.Part(0);
            int            timeout  = (int)left[0];
            // string host = (string) symbol[1];
            // long port = -1;
            // if (symbol.Length > 2)
            //  port = (long) symbol[2];
            RCBot  bot    = runner.GetBot(closure.Bot);
            long   handle = bot.New();
            Client client;

            if (protocol.Equals("http"))
            {
                client = new TcpHttpClient(handle, symbol);
            }
            else if (protocol.Equals("tcp"))
            {
                client = new TcpClient(handle, symbol, new TcpProtocol(), timeout);
            }
            else if (protocol.Equals("udp"))
            {
                throw new NotImplementedException("No udp sockets yet");
            }
            else if (protocol.Equals("cube"))
            {
                throw new NotImplementedException();
                // client = new CubeClient (handle, symbol);
            }
            else
            {
                throw new NotImplementedException("Unknown protocol: " + protocol);
            }
            bot.Put(handle, client);
            client.Open(runner, closure);
        }