473,385 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

socket communication over content switch

Hi,

I have a simple client server application which communicates through sockets. There is a content switch in between client and server that routes the request to a proper server machine. This content switch pings the server machines every 5 millisec to check the heartbeat. My server app is raising an System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> whenever the content switch is pinging and is trying to read the stream.

Inorder to avoid this I have used networkstream.dataavailable to check if there is request from the client or if it is just a ping from the contentswitch. But the networkstream.dataavailable is returning false even if there is data or a true request from true client. I can't use the IP to differentiate between contentswitch and actual client because the ip's are masked. How would I get rid of the I/O exception and read data when available.



My code snippet:

private void ProcessRequest(object param)

{

Socket inSocket = (Socket)param;

if (inSocket.Connected)

{

string clientIP = IPAddress.Parse(((IPEndPoint)inSocket.RemoteEndPoi nt).Address.ToString()).ToString();

NetworkStream networkStream = null;

System.IO.StreamWriter streamWriter = null;

System.IO.StreamReader streamReader = null;

try

{

networkStream = new NetworkStream(inSocket);

streamWriter = new System.IO.StreamWriter(networkStream);

streamReader = new System.IO.StreamReader(networkStream);

// Read data.



if (!networkStream.DataAvailable)

return; ---- This is always returning false. even if data is present. why is that so?



string line = streamReader.ReadLine();

//Parse data

..


//Report result back to the client

streamWriter.WriteLine((int)ret);

streamWriter.Flush();

}

catch (Exception ex)

{

Logger.write(ex.message.tostring());

}

finally

{

if (streamWriter != null) streamWriter.Close();

if (streamReader != null) streamReader.Close();

if (networkStream != null) networkStream.Close();

inSocket.Close();

}

}



Any help would be greatly appreciated. Thanks
Nov 20 '07 #1
0 828

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: faktujaa | last post by:
Hi, I am having some problem with callback used in socket implementation. private static void Connect(string strPrtrIPAddr, int intPrtrPort, ref Socket rsocClient) { try { // Create remote end...
0
by: Hardy Wang | last post by:
Hi, I developed an application to read email from POP3 server. Some of the codes are below: ------------------------------------------------------------------------------- Server = new...
3
by: Ricardo Quintanilla | last post by:
i had a problem whom i do not know how to explain. i was using a TcpClient (System.Net.Sockets.TcpClient) object to send and receive data to an AS400 socket. Two months ago it started to work...
4
by: Sa¹o Zagoranski | last post by:
Hi! I'm writing a simple 3D First person shooter game. It is a multiplayer game, where all the players connect to one server.
2
by: Rene Sørensen | last post by:
We are 4 students working on a assignment, that our teacher gave use, normally we do this is C++, but the 4 of us, use C# more often that C++ so… We made a small games called reversi, now our job...
1
by: Thomas René Sidor | last post by:
Hello Having been trying to find the root of this problem for several days I now hope that you can help me. I'm implementing a distributed file system - consisting of, at the moment, a...
4
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket...
0
by: =?Utf-8?B?QWxwZXIgQUtDQVlPWg==?= | last post by:
Hello, First of all I wish you a good day. My help request is about .NET asynchrounus socket communication. I have developed Server-Client Windows Forms .NET applications in VC++ .NET v2003. I...
0
by: Mangabasi | last post by:
Howdy, I would like to use the Synthesis Toolkit for a demo. I downloaded the STK from http://ccrma.stanford.edu/software/stk/index.html. It seems very powerful and user friendly. There are...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.