Hey,
I'm using a TcpClient to create HTTP requests to my web-server (I know
of HttpWebRequest, it is mandatory for me to use TcpClient.).
Here's my code:
TcpClient tcp = new TcpClient(SERVER_IP, SERVER_PORT);
tcp.NoDelay = true;
string data = "GET http://" + SERVER_IP + SERVER_PORT + "/getData?id=1
HTTP/1.1\r\nConnection: Keep-Alive\r\n\r\n";
byte[] buffer = Encoding.ASCII.GetBytes(data);
tcp.GetStream().Write(buffer, 0, buffer.Length);
tcp.GetStream().Flush();
//Wait
int bufferSize = tcp.Available;
buffer = new byte[bufferSize];
tcp.GetStream().Read(buffer, 0, bufferSize);
result = Encoding.UTF8.GetString(buffer);
This code works great.
The problem is, I dont want to re-create the TcpClient for each
request,
But when I try to create an already used TcpClient, although the Write
method doesnt throw any exception, no data is recieved and my web-
server's log show nothing.
What am I missing?
Thanks!
--sternr