這裏是你的樣品。
private string getHTTP(string url)
{
TcpClient clientSocket = new TcpClient();
NetworkStream networkStream = null;
long port = 7777;
try
{
try
{
clientSocket.Connect(url,port);
}
catch { MessageBox.Show("Server is not Working", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return "Server is not working"; }
byte[] sendbyte = Encoding.ASCII.GetBytes(url);
networkStream = clientSocket.GetStream();
networkStream.Write(sendbyte, 0, sendbyte.Length);
networkStream.Flush();
}
catch { MessageBox.Show("Streaming Error", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return "Error"; }
// receive Message from DNS Server
byte[] receivedata = new byte[clientSocket.ReceiveBufferSize];
networkStream.Read(receivedata, 0, clientSocket.ReceiveBufferSize);
string urlnew = Encoding.ASCII.GetString(receivedata);
return urlnew;
}
更應該參考this link
將插座打開使用HTTP進行通信?你看過HttpWebClient類嗎? http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx – 2011-12-17 03:38:19
是的套接字將使用HTTP通信! – Xris 2011-12-17 04:01:56