public static string SocketSendReceive(string request)
{
Byte[] bytesSent = Encoding.ASCII.GetBytes(request);
Byte[] bytesReceived = new Byte[1024];
// Create a socket connection with the specified server and port.
Socket s = ConnectSocket();
if (s == null)
return ("Connection failed");
// Send request to the server.
s.Send(bytesSent, bytesSent.Length, 0);
// Receive the server home page content.
int bytes = 0;
string page = "Default HTML page on " + server + ":\r\n";
// The following will block until te page is transmitted.
do
{
bytes = s.Receive(bytesReceived, bytesReceived.Length, 0);
Encoding gb2312 = Encoding.GetEncoding("gb2312");//将读取的字节数转换为字符串