473,748 Members | 10,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

socket communication over content switch

1 New Member
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.IOExc eption: 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.d ataavailable to check if there is request from the client or if it is just a ping from the contentswitch. But the networkstream.d ataavailable 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.Conne cted)

{

string clientIP = IPAddress.Parse (((IPEndPoint)i nSocket.RemoteE ndPoint).Addres s.ToString()).T oString();

NetworkStream networkStream = null;

System.IO.Strea mWriter streamWriter = null;

System.IO.Strea mReader streamReader = null;

try

{

networkStream = new NetworkStream(i nSocket);

streamWriter = new System.IO.Strea mWriter(network Stream);

streamReader = new System.IO.Strea mReader(network Stream);

// Read data.



if (!networkStream .DataAvailable)

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



string line = streamReader.Re adLine();

//Parse data

..


//Report result back to the client

streamWriter.Wr iteLine((int)re t);

streamWriter.Fl ush();

}

catch (Exception ex)

{

Logger.write(ex .message.tostri ng());

}

finally

{

if (streamWriter != null) streamWriter.Cl ose();

if (streamReader != null) streamReader.Cl ose();

if (networkStream != null) networkStream.C lose();

inSocket.Close( );

}

}



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

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

Similar topics

4
2271
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 point. System.Net.IPAddress IPAddress = System.Net.IPAddress.Parse(strPrtrIPAddr); System.Net.IPEndPoint IPEndPoint = new System.Net.IPEndPoint(IPAddress,
0
1305
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 TcpClient(_MailServer, 110); ...... private string sendCommand(string command) { byte szData; NetStrm = Server.GetStream();
3
28654
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 slowly, about 4 seconds between send and receive. In our production environment with hundreds of transactions it was truly costly. a while ago i changed de TcpClient object. Now i am using a Socket (System.Net.Sockets.Socket) object and it...
4
2351
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
2879
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 is to make a server, none of us know nothing about socket programming in C#, but we founds some guides for this, and now ,got a server running, but we have some problems though. We have 2 scenario, one where we use a telnet connection and one...
1
1965
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 testing client (C), a http-server (H) and a file server (F) - with the following setup: H acts as an external interface to F, that is any given C connect to
4
3604
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 client and asynchronous socket server example code provided in the .NET framework developers guide is a great start but I have not dealt with sockets before and I am struggling with something. From what I can tell the sample server code ...
0
2604
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 have several problems re-establishin connection between peers. Below are my problem cases after closing of the first successfull communication; #1) I re-start the Server to accept connection requests. While it is waiting, I run the Client. It is...
0
1775
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 bindings for socket connections and TCL gui examples. I would like to get one of the demo samples work with Python/wxPython. I am including the TCL code for the drums demo (this was the shortest one). Has anybody converted this to wxPython? ...
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.