public void Run() { while (socket.IsBound) { try { XLoper name = BinaryCodec.Decode(stream); if (name.Type != XLoper.xlTypeStr) { throw new Exception("Protocol Error: expecting function name"); } XLoper argc = BinaryCodec.Decode(stream); if (argc.Type != XLoper.xlTypeInt) { throw new Exception("Protocol Error: expecting arg count"); } XLoper[] args = new XLoper[argc.W]; for (int i = 0; i < argc.W; i++) { args[i] = BinaryCodec.Decode(stream); } try { XLoper res = handler.Execute(name.Str, args); BinaryCodec.Encode(res, stream); } catch (RequestException re) { XLoper x = new XLoper(); x.Type = XLoper.xlTypeStr; x.Str = re.Message; BinaryCodec.Encode(x, stream); } } catch (Exception e) { Console.WriteLine(e.StackTrace); socket.Close(); } } }