111,098
社区成员




public static string SendSocketFullAutoTicketInfo(string sendContentText, string hashKey)
{
string stringData = "";
Socket socket = null; ;
string qString = "";
string ipAndPort = "";
try
{
qString = "请求开始时间:" + DateTime.Now + " 请求内容" + sendContentText;
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
byte[] byteMessage;
if (!socket.Connected)
{
ipAndPort = SelectServerIp(hashKey);///获取服务器IP好端口
IPAddress serverIp = IPAddress.Parse(ipAndPort.Split(':')[0]);
int serverPort = Convert.ToInt32(ipAndPort.Split(':')[1]);
IPEndPoint iep = new IPEndPoint(serverIp, serverPort);
socket.Connect(iep);
}
byteMessage = Encoding.ASCII.GetBytes(sendContentText);
socket.Send(byteMessage);
byteMessage = new byte[20480];
int resv = socket.Receive(byteMessage);
stringData = Encoding.GetEncoding("GBK").GetString(byteMessage, 0, resv);
qString += " 服务器:" + ipAndPort + "; 请求返回时间:" + DateTime.Now + "; 请求返回内容:" + stringData;
}
catch (Exception ex)
{
stringData = "服务器无响应--请检查服务器";
qString += " 服务器:" + ipAndPort + "; 请求返回时间:" + DateTime.Now + "; 请求返回内容:" + stringData;
LogHelp.LogException("服务器无响应--请检查服务器", qString, ex, FullAutoTicketConfig.InnerMonitorMailList);
throw ex;
}
finally
{
if (socket != null && socket.Connected)
{
try
{
//socket.Disconnect(false);
socket.Shutdown(SocketShutdown.Both);
socket.Close();
socket = null;
}
catch (Exception closeEx)
{
LogHelper.WriteLog("异常", string.Format("Request_Response11_{0}.txt", DateTime.Now.ToString("yyyyMMddHH")), closeEx.Message);
}
}
}
return stringData;
}