473,395 Members | 1,948 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,395 software developers and data experts.

IP address for a socket service

I have a problem. I have two instances of a client-server application
running on two different machines A and B.

A has a listening service, that listens for connections from B
B has a listening service, that listens for connections from A

The problem is what IP to bind the listening service to. I can find
all local ip-addresses this way:
IPHostEntry hostEntry =
Dns.GetHostEntry(Dns.GetHostName());

foreach (IPAddress ipAdress in hostEntry.AddressList)
{
Console.WriteLine(ipAdress.ToString());
}

But how on earth do I know which one to bind and listen to? There's a
mix of IPv4 and IPv6 addresses, virtual vmware addresses, one from the
wireless wifi card and one from the ethernet cable.

Argh...

The server component I'm using has a single "void Listen(string ip,
int port)" method. Even if I manage to listen on all addresses, how
will B know which one of A's to connect to? A sends B it's ip-address
using a different schema (but's it in a common database). But I still
need to put A's "external" address down.
Jan 16 '08 #1
6 5065
Hi

There is an overload of the constructor of TcpListener that let you select
the IP, even more the variant where you only select a port is marked as
deprecated.
If no IP is especified it will use all the IPs in the system.

Of course the client has to know the ip or the name of the server, otherwise
it's imopssible to establish a communication.
--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
<pa*************@gmail.comwrote in message
news:2a**********************************@n20g2000 hsh.googlegroups.com...
>I have a problem. I have two instances of a client-server application
running on two different machines A and B.

A has a listening service, that listens for connections from B
B has a listening service, that listens for connections from A

The problem is what IP to bind the listening service to. I can find
all local ip-addresses this way:
IPHostEntry hostEntry =
Dns.GetHostEntry(Dns.GetHostName());

foreach (IPAddress ipAdress in hostEntry.AddressList)
{
Console.WriteLine(ipAdress.ToString());
}

But how on earth do I know which one to bind and listen to? There's a
mix of IPv4 and IPv6 addresses, virtual vmware addresses, one from the
wireless wifi card and one from the ethernet cable.

Argh...

The server component I'm using has a single "void Listen(string ip,
int port)" method. Even if I manage to listen on all addresses, how
will B know which one of A's to connect to? A sends B it's ip-address
using a different schema (but's it in a common database). But I still
need to put A's "external" address down.

Jan 16 '08 #2
pa*************@gmail.com wrote:
I have a problem. I have two instances of a client-server application
running on two different machines A and B.

A has a listening service, that listens for connections from B
B has a listening service, that listens for connections from A

The problem is what IP to bind the listening service to. I can find
all local ip-addresses this way:
[...]
But how on earth do I know which one to bind and listen to? There's a
mix of IPv4 and IPv6 addresses, virtual vmware addresses, one from the
wireless wifi card and one from the ethernet cable.
Yup. Knowing which one to bind to depends on the network you want to listen on.
If A is publishing its IP to B, then it really doesn't matter what B publishes
on does it? You could just create your IPEndPoint using IPAddress.Any as the
IPAdress argument to just grab whatever the system thinks is best, i.e.:

Int32 port = 10101;
IPEndPoint myEndPoint = new IPEndPoint(IPAddress.Any, port);

Chris.
Jan 16 '08 #3
on does it? You could just create your IPEndPoint using IPAddress.Any as
the
IPAdress argument to just grab whatever the system thinks is best, i.e.:
On client-side, IPAddress.Any lets the system choose one (and only one). On
server side, though, IPAddress.Any results in using *all* addresses and
interfaces.
>
Int32 port = 10101;
IPEndPoint myEndPoint = new IPEndPoint(IPAddress.Any, port);

Chris.

Jan 16 '08 #4
On Jan 16, 2:32 pm, Chris Shepherd <c...@nospam.chsh.cawrote:
paal.andreas...@gmail.com wrote:
I have a problem. I have two instances of a client-server application
running on two different machines A and B.
A has a listening service, that listens for connections from B
B has a listening service, that listens for connections from A
The problem is what IP to bind the listening service to. I can find
all local ip-addresses this way:
[...]
But how on earth do I know which one to bind and listen to? There's a
mix of IPv4 and IPv6 addresses, virtual vmware addresses, one from the
wireless wifi card and one from the ethernet cable.

Yup. Knowing which one to bind to depends on the network you want to listen on.
If A is publishing its IP to B, then it really doesn't matter what B publishes
on does it? You could just create your IPEndPoint using IPAddress.Any as the
IPAdress argument to just grab whatever the system thinks is best, i.e.:

Int32 port = 10101;
IPEndPoint myEndPoint = new IPEndPoint(IPAddress.Any, port);

Chris.
On the server-side I can have the service bind to IPAddress.Any ok,
but the client still needs to know the "correct" IP address for the
server. Iterating thought hostEntry.AddressList returns several
addresses, how do I know which one to use? I'd really like to automate
this and not ask the user "which of the following IP addresses is the
right one" if you follow.

Like I said, I put the IP address in a SQL database which is shared
between the clients. The client is then supposed to use this IP to
access the service directly. But on a given machine AddressList might
return several different IP addresses, but only one is actually
enabling access from outside the computer. The problem is to identify
which one I should but in the database.

Example, on a give computer I get two different IP Addressen in the
hostEntry.AddressList:

0: 10.70.0.125 InterNetwork
1: 10.0.0.14 InterNetwork

In this case I know that entry 0 is a VPN tunnel to another network
and is not interesting. It's 10.0.0.14 that my service is accessible
from the other clients in the network.

Can I detect which of these are used with the default gateway? Or is
that a dead end?
Jan 16 '08 #5
pa*************@gmail.com wrote:
On the server-side I can have the service bind to IPAddress.Any ok,
but the client still needs to know the "correct" IP address for the
server. Iterating thought hostEntry.AddressList returns several
addresses, how do I know which one to use? I'd really like to automate
this and not ask the user "which of the following IP addresses is the
right one" if you follow.
The difficulty lies in routing tables and knowing how the server can connect to
the client. Why you are publishing the IP of the server to an SQL database is
beyond me because it sounds like you're trying to reinvent DNS. A simple DNS
entry would completely solve this problem, IMO, as you could just see what IP
that hostname resolved to, and have that stored in the application's configuration.

If there were a "proper" solution, I'd think it's the one that involves using
the technologies standard to 95% of networks out there.
Chris.
Jan 16 '08 #6
Ben Voigt [C++ MVP] wrote:
>on does it? You could just create your IPEndPoint using IPAddress.Any as
the
IPAdress argument to just grab whatever the system thinks is best, i.e.:

On client-side, IPAddress.Any lets the system choose one (and only one). On
server side, though, IPAddress.Any results in using *all* addresses and
interfaces.
I misunderstood the OP, and was operating under the theory that it was the
client that was needing to publish it's IP to the server, not the other way around.
Chris.
Jan 16 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Alexander N. Spitzer | last post by:
If I have a machine with 3 virtual IP addresses (192.168.1.), how can I start 3 instances of the same RMI application (each started with different properties/configs), each listening on the port...
0
by: Gregory Hassett | last post by:
Hello, I want to periodically send a TCP packet to a peer, always from the same source port. That is, each packet will come from my local ip address, port 8801, and go to the peer's ip address,...
1
by: Ezz | last post by:
I have an interesting problem...and its one of those where I know what I want but don't know how to ask it =) I have an eCommerce application that uses Paypal for its payment gateway. It is an...
0
by: ArkJ | last post by:
Hello. I have a little problem. I created a little Service which uses SIP, all works rather well, but when I want to shut it down in the Services panel, it looks as if it's shut down, but in fact...
1
by: =?Utf-8?B?Um9kcmlnbyBHYXJjw61h?= | last post by:
I have a client making web service calls to a NLB cluster. When the cluster was comprised by two machines everything went fine serving near two hundred service requests per second. Now I increased...
3
by: Abdulla Herzallah | last post by:
Hi everyone I don't know if I am posting this to the right newsgroup but it is the closest I found, in case you think you can advice me to another newsgroup please feel free to do so. I am so...
3
by: ChristianProgrammer | last post by:
Its been a month and a half now. I have tried to get my WSSF web service to reference a class library that IS a Socket Client. The Socket Client in question runs fine when called by a testing exe....
9
by: pbd22 | last post by:
Hi. I am getting the below error: Event Type: Error Event Source: PeskyService Event Category: None Event ID: 0 Date: 1/30/2008 Time: 5:49:10 PM User: N/A
5
by: Timothy Grant | last post by:
On Tue, Aug 5, 2008 at 2:50 PM, David York <davideyork@gmail.comwrote: I'm not sure what you are trying to accomplish. The machine I'm typing this on has a 192.168.x.x number. The router that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.