public void Send(string host, int port, string sendData, UserToken token) { sendData = string.Format("?d={0}", UrlEncode(sendData + "&sign=" + CreateSigin(sendData))); byte[] data = System.Text.Encoding.UTF8.GetBytes(sendData); byte[] head = BitConverter.GetBytes(data.Length); byte[] result = new byte[data.Length + head.Length]; Buffer.BlockCopy(head, 0, result, 0, head.Length); Buffer.BlockCopy(data, 0, result, head.Length, data.Length); Send(host, port, result, token); }
private void SetConfig(string host, int port, int actionId, UserToken token, string pwd) { ConfigurationUtils.GetInstance().updateSeeting("User.Host", host); ConfigurationUtils.GetInstance().updateSeeting("User.Port", port.ToString()); ConfigurationUtils.GetInstance().updateSeeting("User.ActionId", actionId.ToString()); ConfigurationUtils.GetInstance().updateSeeting("User.GameType", token.GameType.ToString()); ConfigurationUtils.GetInstance().updateSeeting("User.ServerID", token.ServerID.ToString()); ConfigurationUtils.GetInstance().updateSeeting("User.RetailID", token.RetailID); ConfigurationUtils.GetInstance().updateSeeting("User.Pid", token.Pid); ConfigurationUtils.GetInstance().updateSeeting("User.Pwd", pwd); ConfigurationUtils.GetInstance().updateSeeting("User.DeviceID", token.DeviceID); ConfigurationUtils.GetInstance().updateSeeting("User.MobileType", token.MobileType.ToString()); ConfigurationUtils.GetInstance().save(); }
public void Send(string host, int port, byte[] sendData, UserToken token) { string endpoint = string.Format("{0}:{1}", host, port); SocketClient client = null; if (!_clientDict.ContainsKey(endpoint)) { client = new SocketClient(host, port, bufferSize); client.ReceiveHandle += ReceiveCompleted; _clientDict.Add(endpoint, client); } else { client = _clientDict[endpoint]; } if (client.Socket.Connected || client.Connect()) { client.SendAsync(sendData); client.ReceiveAsyncResult(); } else { throw new Exception("连接服务器失败"); } }