public static void AcceptCallback(IAsyncResult ar) { // Signal the main thread to continue. AllDone.Set(); // Get the socket that handles the client request. var listener = (Socket)ar.AsyncState; var handler = listener.EndAccept(ar); // Create the state object. var state = new StateObject { WorkSocket = handler }; States.Add(state.Id, state); var startMsg = new Message { Command = "AGTSTART", Type = Message.MessageType.Notification, OrigId = "Agent server", ProcessId = "26621", InvokeId = "0", Contents = new List<string> { "AGENT_STARTUP" } }; Send(state, new List<string> { startMsg.RawMessage }); }
public static Message ParseMessage(string raw) { var ret = new Message(); ret.RawMessage = raw; ret.Command = raw.Substring(0, 20).Trim(); ret.Type = (MessageType) char.Parse(raw.Substring(20, 1)); ret.OrigId = raw.Substring(21, 20).Trim(); ret.ProcessId = raw.Substring(41, 6).Trim(); ret.InvokeId = raw.Substring(47, 4).Trim(); ret.Contents = new List<string>(); foreach (var data in raw.Substring(55).Replace(_END_OF_LINE.ToString(), string.Empty).Split(_RECORD_SEPERATOR)) { if (!string.IsNullOrEmpty(data)) ret.Contents.Add(data); } return ret; }
public void Send(Message data) { data.InvokeId = (_invokeIdSequence++).ToString(); if (MessageSent != null) MessageSent(this, new MessageSentEventArgs { Message = data }); Send(data.RawMessage); }
public void SendCommand(Message command) { _client.Send(command); }
private static void _WriteMessage(Socket sock, Message msg) { var writer = new StreamWriter(new NetworkStream(sock, true)); var rawMsg = msg.RawMessage; Console.WriteLine("Sent ({0}):" + rawMsg, DateTime.Now); writer.Write(rawMsg); writer.Flush(); Thread.Sleep(50); }
private static Message CreateMessage(string command, Message.MessageType type, List<string> contents) { return new Message { Command = command, Type = type, OrigId = "Agent server", ProcessId = "25538", InvokeId = "0", Contents = contents }; }