private TransDKJ() { this.msgSendReceiver = ServerConn.ConnServer(); if (this.msgSendReceiver == null) { throw new Exception("MsgSendReceiver错误!"); } }
public DKJtest() { //连接服务器,创建通讯类 MsgSendReceiver msr = ServerConn.ConnServer(); if (msr == null) { Console.Out.WriteLine("连接服务器失败!"); } else { dkj = TransDKJ.GetInstance(); } }
public void SendMsg(Msg msg) { if (ServerConn.SocketTest()) { string msgStr = string.Format("{0,-4}", (int)msg.GetProtocol()) + string.Format("{0,-4}", (int)msg.GetTopService()) + string.Format("{0,-4}", msg.GetLowService()) + string.Format("{0,-4}", msg.GetLength()) + msg.GetContent().InnerXml; byte[] buffer = Encoding.UTF8.GetBytes(msgStr); mySocket.Send(buffer); } else { throw new Exception("连接断开!"); } }
/** * 关闭Socket * 成功关闭返回1;不成功关闭返回0 */ public int CloseSocket() { XmlDocument document = new XmlDocument(); XmlElement disconnect = document.CreateElement("disconnect");//CreateElement(节点名称) document.AppendChild(disconnect); Msg msg = new Msg(EProtocol.EP_Disconnect, ETopService.ET_DKJ, 0, document); this.msgSendReceiver.SendMsg(msg); try { ServerConn.SocketClose(); return(1); } catch (Exception) { return(0); } }