public void EvalListen(RCRunner runner, RCClosure closure, RCSymbol right) { if (right.Count != 1) { throw new Exception("listen takes exactly one protocol,port"); } string protocol = (string)right[0].Part(0); long port = (long)right[0].Part(1); RCBot bot = runner.GetBot(closure.Bot); long handle = bot.New(); Server server; if (protocol.Equals("http")) { throw new NotImplementedException("http server not ready yet"); } else if (protocol.Equals("tcp")) { server = new TcpServer(handle, port, new TcpProtocol()); } else if (protocol.Equals("udp")) { throw new ArgumentException("No udp sockets yet"); } else { throw new ArgumentException("Unknown protocol: " + protocol); } bot.Put(handle, server); server.Listen(runner, closure); }
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); }