PC Review


Reply
Thread Tools Rate Thread

How can a .net socket server listen to all the IPAddresses of serv

 
 
Lokanath Chhatria
Guest
Posts: n/a
 
      9th May 2009
We have a socket server program and a socket client program.

The server, where the socket server program runs, has two network adapters
and hence two IP Addresses.

If the server program listens to an IP Address Endpoint which client can't
resolve, the client doesn't work.

The server program's code is like:

// Establish the local endpoint for the socket.

IPAddress hostaddress = IPAddress.Parse(socketInfo.SourceIP);

IPEndPoint localEndPoint = new IPEndPoint(hostaddress, socketInfo.SourcePort);

// Create a TCP/IP socket.
listenerSocket = new Socket(AddressFamily.InterNetwork,

SocketType.Stream, ProtocolType.Tcp);

listenerSocket.Bind(localEndPoint);

i.e it listens to one of the IP Addresses.

To solve the problem, I changed

IPEndPoint localEndPoint = new IPEndPoint(hostaddress, socketInfo.SourcePort);
to
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any,
socketInfo.SourcePort);

As "IPAddress.Any" would listen to both the IP Addresses for the given port.

But this did not work.

Can anyone tell me how to make a socket server listen to all the IP Address
of the server
 
Reply With Quote
 
 
 
 
Lokanath Chhatria
Guest
Posts: n/a
 
      11th May 2009


"Peter Duniho" wrote:

> On Sat, 09 May 2009 04:47:01 -0700, Lokanath Chhatria
> <(E-Mail Removed)> wrote:
>
> > [...]
> > IPEndPoint localEndPoint = new IPEndPoint(hostaddress,
> > socketInfo.SourcePort);
> > to
> > IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any,
> > socketInfo.SourcePort);
> >
> > As "IPAddress.Any" would listen to both the IP Addresses for the given
> > port.
> >
> > But this did not work.

>
> It should. If the rest of the code is otherwise correct and it doesn't
> work with IPAddress.Any, you have a configuration problem.
>




Thanks for the reply..The rest of the code is fine and error free I beleive,
How should I detect a configuration problem?
The socket server program is running on Windows Server 2003 with 2 network
adapters, the ip address information for the two adapters is

1st network adapter:
IP Address ------- 10.0.30.6
Subnet mask ------255.0.0.0
Default Gateway---10.0.30.2

2nd network adapter:
IP Address -------- 192.168.112.142
Subnet mask ----- 255.255.255.0
Default Gateway ---192.168.112.2

The socket client program is running on Windows XP machine with the IP
Address:

IP Address ------ 10.0.30.10
Subnet mast ----255.0.0.0
Default Gateway--10.0.30.2

The client program gets to connect to the server when the server listens to
10.0.30.6, but if server listens to 192.168.112.142, the client doesn;t
connect.

Even when I have put IPAddress.Any, it doesn't seem to be working for
192.168.112.142.

Kindly help.
 
Reply With Quote
 
Lokanath Chhatria
Guest
Posts: n/a
 
      11th May 2009


"Peter Duniho" wrote:

> On Sun, 10 May 2009 22:14:01 -0700, Lokanath Chhatria
> <(E-Mail Removed)> wrote:
>
> > [...]
> > How should I detect a configuration problem?

>
> It seems you have already _detected_ the problem. The question is how to
> fix it.
>
> > The socket server program is running on Windows Server 2003 with 2
> > network
> > adapters, the ip address information for the two adapters is
> >
> > 1st network adapter:
> > IP Address ------- 10.0.30.6 [...]
> >
> > 2nd network adapter:
> > IP Address -------- 192.168.112.142 [...]
> >
> > The socket client program is running on Windows XP machine with the IP
> > Address:
> >
> > IP Address ------ 10.0.30.10 [...]
> >
> > The client program gets to connect to the server when the server listens
> > to
> > 10.0.30.6, but if server listens to 192.168.112.142, the client doesn;t
> > connect.
> >
> > Even when I have put IPAddress.Any, it doesn't seem to be working for
> > 192.168.112.142.

>
> Your question is vague. Are you saying that you are trying to get a
> client that has as its only IP address "10.0.30.10" to connect to your
> server using IP address "192.168.112.142"?
>
> If so, then there's probably no configuration problem, just wrong
> expectations on your part.
>
> The client on "10.0.30.10" is not in the same sub-net as the network
> adapter using "192.168.112.142". It's just not going to be possible for
> that client to access the server on that IP address.
>
> My guess is that everything is working just fine. If you want to test the
> server on the address "192.168.112.142", you will need to use a client
> that's on the same subnet (i.e. has an IP address of "192.168.112.???"
> where "???" is some actual number), or you need to configure the router
> for that network segment to forward traffic to the server's
> "192.168.112.142" address (and even then, whether you can get at the
> router from your client using "10.0.30.10" is going to be configuration
> dependent).
>
> Pete
>



Thanks Pete,
I changed the subnet masks, so that it is same for both the IP Addresses.
It is working fine now


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listening socket still listen after first connection =?Utf-8?B?aXdkdTE1?= Microsoft VB .NET 1 29th Dec 2006 02:01 AM
Socket Listen for single connection yofnik@comcast.net Microsoft Dot NET Framework 1 3rd Apr 2006 03:01 PM
Socket Listen for single connection Yofnik Microsoft Dot NET 1 1st Apr 2006 12:25 PM
Socket.Listen() maximum John J. Hughes II Microsoft C# .NET 2 8th Feb 2006 06:30 PM
Socket Cli & Serv on localhost? EdgarBM Microsoft C# .NET 0 29th Jan 2004 03:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:05 AM.