/// <summary> /// 进入区块链 /// </summary> /// <returns>状态</returns> public int Enter() { Binary bw = new Binary(); bw.WriteInt(DataCenter.ServerChatService.Port); bw.WriteInt(DataCenter.IsFull ? 1 : 0); bw.WriteString(DataCenter.UserID); bw.WriteString(DataCenter.UserName); byte[] bytes = bw.GetBytes(); int ret = Send(new CMessage(GroupID, ServiceID, FUNCTIONID_ENTER, SessionID, DataCenter.ChatRequestID, SocketID, 0, CompressType, bytes.Length, bytes)); bw.Close(); return(ret); }
public static void SaveJira(Jira jira) { StringBuilder sb = new StringBuilder(); sb.Append(@"<?xml version='1.0' encoding='gb2312' ?>"); sb.Append("\r\n"); sb.Append(jira.GetXml()); Binary bi = new Binary(); bi.WriteBytes(System.Text.Encoding.Default.GetBytes(sb.ToString())); byte[] sendData = bi.GetBytes(); HttpPostService.Post(DataCenter.ServerAddr + "giraservice?func=savegira&gid=" + jira.JiraID, sendData, true); m_dataDic[jira.JiraID] = sb.ToString(); }
/// <summary> /// 发送消息 /// </summary> /// <param name="message">消息</param> public virtual int Send(CMessage message) { Binary bw = new Binary(); byte[] body = message.m_body; int bodyLength = message.m_bodyLength; int uncBodyLength = bodyLength; if (message.m_compressType == COMPRESSTYPE_GZIP) { using (MemoryStream cms = new MemoryStream()) { using (GZipStream gzip = new GZipStream(cms, CompressionMode.Compress)) { gzip.Write(body, 0, body.Length); } body = cms.ToArray(); bodyLength = body.Length; } } int len = sizeof(int) * 4 + bodyLength + sizeof(short) * 3 + sizeof(byte) * 2; bw.WriteInt(len); bw.WriteShort((short)message.m_groupID); bw.WriteShort((short)message.m_serviceID); bw.WriteShort((short)message.m_functionID); bw.WriteInt(message.m_sessionID); bw.WriteInt(message.m_requestID); bw.WriteByte((byte)message.m_state); bw.WriteByte((byte)message.m_compressType); bw.WriteInt(uncBodyLength); bw.WriteBytes(body); byte[] bytes = bw.GetBytes(); int length = bytes.Length; IntPtr ptr = Marshal.AllocHGlobal(sizeof(byte) * length); for (int i = 0; i < length; i++) { IntPtr iptr = (IntPtr)((int)ptr + i); Marshal.WriteByte(iptr, bytes[i]); } int ret = SendByClient(message.m_socketID, ptr, length); m_upFlow += ret; Marshal.FreeHGlobal(ptr); bw.Close(); return(ret); }
/// <summary> /// 发送消息 /// </summary> /// <param name="userID">方法ID</param> /// <param name="tokens">请求ID</param> /// <param name="chatData">发送字符</param> public int Send(int functionID, int requestID, ChatData chatData) { Binary bw = new Binary(); bw.WriteString(chatData.m_aes); bw.WriteString(chatData.m_tokens); bw.WriteString(chatData.m_from); bw.WriteString(chatData.m_to); bw.WriteString(chatData.m_content); bw.WriteInt(chatData.m_bodyLength); if (chatData.m_bodyLength > 0) { bw.WriteBytes(chatData.m_body); } byte[] bytes = bw.GetBytes(); int ret = Send(new CMessage(GroupID, ServiceID, functionID, SessionID, requestID, SocketID, 0, CompressType, bytes.Length, bytes)); bw.Close(); return(ret); }
/// <summary> /// 保持活跃 /// </summary> /// <param name="socketID">套接字ID</param> /// <returns>状态</returns> public virtual int KeepAlive(int socketID) { Binary bw = new Binary(); bw.WriteInt((int)4); byte[] bytes = bw.GetBytes(); int length = bytes.Length; IntPtr ptr = Marshal.AllocHGlobal(sizeof(byte) * length); for (int i = 0; i < length; i++) { IntPtr iptr = (IntPtr)((int)ptr + i); Marshal.WriteByte(iptr, bytes[i]); } int ret = SendByClient(socketID, ptr, length); Marshal.FreeHGlobal(ptr); bw.Close(); return(ret); }
/// <summary> /// 发送POST数据 /// </summary> /// <param name="message">消息</param> /// <returns>返回消息</returns> public int SendRequest(CMessage message) { Binary bw = new Binary(); byte[] body = message.m_body; int bodyLength = message.m_bodyLength; int uncBodyLength = bodyLength; if (message.m_compressType == COMPRESSTYPE_GZIP) { using (MemoryStream cms = new MemoryStream()) { using (GZipStream gzip = new GZipStream(cms, CompressionMode.Compress)) { gzip.Write(body, 0, body.Length); } body = cms.ToArray(); bodyLength = body.Length; } } int len = sizeof(int) * 4 + bodyLength + sizeof(short) * 3 + sizeof(byte) * 2; bw.WriteInt(len); bw.WriteShort((short)message.m_groupID); bw.WriteShort((short)message.m_serviceID); bw.WriteShort((short)message.m_functionID); bw.WriteInt(message.m_sessionID); bw.WriteInt(message.m_requestID); bw.WriteByte((byte)message.m_state); bw.WriteByte((byte)message.m_compressType); bw.WriteInt(uncBodyLength); bw.WriteBytes(body); byte[] bytes = bw.GetBytes(); int length = bytes.Length; HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(m_url); webReq.Method = "POST"; webReq.ContentType = "application/x-www-form-urlencoded"; webReq.ContentLength = bytes.Length; if (bytes != null) { Stream writer = webReq.GetRequestStream(); writer.Write(bytes, 0, bytes.Length); writer.Close(); } HttpWebResponse response = (HttpWebResponse)webReq.GetResponse(); Stream reader = response.GetResponseStream(); long contentLength = response.ContentLength; byte[] dataArray = new byte[contentLength]; for (int i = 0; i < contentLength; i++) { dataArray[i] = (byte)reader.ReadByte(); } response.Close(); reader.Dispose(); bw.Close(); int ret = dataArray.Length; UpFlow += ret; IntPtr ptr = Marshal.AllocHGlobal(sizeof(byte) * ret); for (int i = 0; i < ret; i++) { IntPtr iptr = (IntPtr)((int)ptr + i); Marshal.WriteByte(iptr, dataArray[i]); } BaseService.CallBack(message.m_socketID, 0, ptr, ret); Marshal.FreeHGlobal(ptr); return(ret); }