public void Start() { TcpClient client = new TcpClient(_hostname, _port); _xport = new TcpMessageTransport(client); _format = new DipMessageFormat(); _channel = new MessageChannel(_xport, _format); _channel.MessageReceived += OnMessageReceived; }
public RequestContext(MessageChannel channel, int ackNumber) { _channel = channel; _ackNumber = ackNumber; }
private void OnChannelClosed(MessageChannel channel) { Console.WriteLine("channel closed."); _channels.Remove(channel); }
private void MakeActionAndDispatch(Message msg, MessageChannel channel) { UserAction request = null; RequestContext context = new RequestContext(channel, msg.SequenceNumber); if (msg.OpCode == MessageOpCode.GetObject) { string path = GetString(msg, "path"); if (path == null) context.NegativeAcknowledge(); request = new GetObjectAction(context, path); } else if (msg.OpCode == MessageOpCode.PutObject) { string path = GetString(msg, "path"); DObject value = GetObject(msg, "value"); if (path == null) context.NegativeAcknowledge(); if (value == null) context.NegativeAcknowledge(); request = new PutObjectAction(context, path, value); } else if (msg.OpCode == MessageOpCode.DoScript) { string trigger = GetString(msg, "when"); string body = GetString(msg, "do"); if (trigger == null) context.NegativeAcknowledge(); if (body == null) context.NegativeAcknowledge(); request = new DoScriptAction(context, trigger, body); } else if (msg.OpCode == MessageOpCode.NG || msg.OpCode == MessageOpCode.OK || msg.OpCode == MessageOpCode.Quote) { // drop it on the floor; not expecting these. return; } else { throw new NotImplementedException(); } Debug.Assert(request != null); _worker.Dispatch(request, context); }