public static string Json(Message message) { JsonSerializer js = new JsonSerializer(); StringWriter str=new StringWriter(); js.Serialize(str, message); return str.ToString(); }
public virtual void SetID(string Id) { this.ID = Id; Message msg = new Message() { Sender = Id, ContentType = "", Content = "设置ID", MsgType = MessageType.SetID, Reciver = "server" }; SendMessage(msg); }
public virtual void SendMessage(Message message) { string str= MessageHelper.Json(message); SendMessage(str); }
public void SendTextMessage(string user,string text) { Message message = new Message(); message.Content = text; message.Sender = this.ID; message.Reciver = user; message.MsgType =MessageType.P2P; message.ContentType = ""; SendMessage(message); }
protected void ProcessMessage(Message message) { if (message.MsgType == MessageType.SetID) { ProcSetID(message); } else if (message.MsgType == MessageType.P2P) { this.Server.SendMessage(message); } if (null != OnReciveMessage) { OnReciveMessage(message); } Server.ReciveMessage(message); }
public void SendTextMessage(string text) { Message message = new Message(); message.Content = text; message.Sender = "Server"; message.Reciver = "Server"; message.MsgType = MessageType.Server; message.ContentType = ""; SendMessage(message); }
public void ProcSetID(Message message) { this.ID = message.Sender; Server.ConnectServer(this); }
public void ReciveMessage(Message message) { if (null != OnReciveMessage) { OnReciveMessage(message); } }
public void SendMessage(Message message) { var toUser = GetConnection(message.Reciver); toUser.SendMessage(message); }