T
Trollpower
Dear NG,
ive got the following problem. Ive made a client which makes a call to
a PHP-Script every 10 Seconds. The result of this call gets parsed.
The call is successfull all the time, but after about 70 calls the
code throws a exception at socket.connect().
Here is the code which i call every 10 Seconds. The method gets called
in a timerevent or in a thread with a waittime of 10 seconds. i tried
both, without success.
private string sendCommandToServer(string command){
connectCount++;
try
{
System.Net.Sockets.Socket socket = new
Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
IPAddress server = IPAddress.Parse("10.12.21.2");
IPEndPoint IPE = new IPEndPoint(server, Convert.ToInt32(80));
socket.Connect(IPE);
Byte[] msg = new Byte[command.Length+5];
msg = Encoding.Default.GetBytes(command+"\r\n");
StringBuilder data_string = new StringBuilder("");
Byte[] bytes = new Byte[1048576];
long bytes_read;
NetworkStream data_stream = new NetworkStream(socket);
int i, bloecke;
bloecke = 0;
socket.Send(msg);
bytes_read = socket.Receive(bytes);
while (bytes_read > 0)
{
for (i = 0; i < bytes_read; i++)
{
data_string.Append((char)(bytes));
}
bytes_read = socket.Receive(bytes);
bloecke = bloecke + 1;
}
socket.Close();
string answer = data_string.ToString();
return answer;
}
catch(Exception ex){
throw new Exception("ConnectionCounter = "+connectCount, ex);
}
}
The command is: POST http://fis.solutions/news.php?gid=4916094959292
If anyone can give me a hint what to do, i would really appreciate it.
Greeting
Jens
ive got the following problem. Ive made a client which makes a call to
a PHP-Script every 10 Seconds. The result of this call gets parsed.
The call is successfull all the time, but after about 70 calls the
code throws a exception at socket.connect().
Here is the code which i call every 10 Seconds. The method gets called
in a timerevent or in a thread with a waittime of 10 seconds. i tried
both, without success.
private string sendCommandToServer(string command){
connectCount++;
try
{
System.Net.Sockets.Socket socket = new
Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
IPAddress server = IPAddress.Parse("10.12.21.2");
IPEndPoint IPE = new IPEndPoint(server, Convert.ToInt32(80));
socket.Connect(IPE);
Byte[] msg = new Byte[command.Length+5];
msg = Encoding.Default.GetBytes(command+"\r\n");
StringBuilder data_string = new StringBuilder("");
Byte[] bytes = new Byte[1048576];
long bytes_read;
NetworkStream data_stream = new NetworkStream(socket);
int i, bloecke;
bloecke = 0;
socket.Send(msg);
bytes_read = socket.Receive(bytes);
while (bytes_read > 0)
{
for (i = 0; i < bytes_read; i++)
{
data_string.Append((char)(bytes));
}
bytes_read = socket.Receive(bytes);
bloecke = bloecke + 1;
}
socket.Close();
string answer = data_string.ToString();
return answer;
}
catch(Exception ex){
throw new Exception("ConnectionCounter = "+connectCount, ex);
}
}
The command is: POST http://fis.solutions/news.php?gid=4916094959292
If anyone can give me a hint what to do, i would really appreciate it.
Greeting
Jens