Re: Multiple closed networks and UDP. Please help me.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Note that it makes absolutely no sense to have three identical subnets connected to the
same computer. There is no way to determine which subnet it came from. The socket
protocol does not provide any capability for distinguishing network adapters. Read the
basic documents.

This is the inevitable consequence of having people who understand nothing about
networking designing networks. The client got it wrong. Probably because they didn't
decide until some time later that they wanted the three subnets to converge.

Available documentation I have checked, e.g., Comer, Volume I (third edition) chapter 10
indicate that subnets have to have disjoint IP address ranges, e.g., 10,11.1.xxx and
10.11.2.xxx. Therefore, your client has a responsibility to create an environment that is
technically viable. Three disjoint subnets with identical IP addresses work fine as long
as they are disjoint. When they stop being disjoint, the addresses must be unique. If
you route them to a common machine, they stop being disjoint.
joe

On Wed, 28 Oct 2009 12:09:49 -0500, Stephen Myers
<""StephenMyers\"@discussions@xxxxxxxxxxxxx"> wrote:

TomChapman wrote:
Stephen Myers > wrote:
Please see my comments below.

TomChapman wrote:
Stephen Myers > wrote:
TomChapman wrote:
I am using Visual C++ version 6.

My next project is to write an application that receives data from
three
UDP data streams. Each data stream will originate from a different
computer. Each of the three computers will be in its own closed
network.

In addition, my program also needs to act as a TCP server on the
regular
(open) network at the customer site. (I will also write a small TCP
client application that will connect to my TCP server program.)

I have worked with TCP many times, but never UDP. I have never worked
with closed networks. I have questions. Please help me.


I assume the computer for my application will need 4 network
connections (4 network cards). One to each closed network and one
to the regular network.
Question: Is this correct? If my 4 network card plan is not correct.
Please tell me how to implement this situation.


Several years ago I wrote my networking classes which are based on MFC
CAsyncSocket. When I open a socket to receive one UDP socket stream
do I
somehow have to stipulate which network to use? Or does this
magically work?

When I open my TCP server socket, how do I stipulate which network
is to
be used?

I have looked at CAsyncSocket and I see nothing about network
connection
selection. How will this work?

I believe that the TCP connection will be assigned based on the IP
address. The three closed networks should be on separate subnets.

Closed 1: 192.168.1.xxx
Closed 2: 192.168.2.xxx
Closed 3: 192.168.3.xxx

Your three NICs will each have an IP address on exactly one of the
networks. Opening a connection to 192.168.2.123 will find the NIC
with the address on the 192.168.2.xxx subnet.

For the UDP connection, I've got less experience. When you open the
CAsyncSocket, you'll specify the known port and turn on the
SO_BROADCAST socket option. At that point you should get broadcasts
from all three NICs. You can use RecvFrom to determine the data
origin.

Steve

I have several follow-up questions:

1) So CAsyncSocket will call my virtual OnReceive method. If this was
TCP I would then call "Receive". Since this is UDP I call
"ReceiveFrom". Correct?
Not exactly. Both methods return exactly one datagram (message).

ReceiveFrom also reports the address that the datagram was received from.

2) The ReceiveFrom method will return 1 or more bytes. I need to
buffer the received data bytes until I determine when I have a
complete packet. If this was TCP I'd have one buffer, but since with
UDP I may receive data from more then one remote computer. So I will
need to maintain multiple buffers, one for each IP that sends me
data. The IP of who is sending the data is provided in a parameter of
the ReceiveFrom method. Is this all correct?
This depends completely on what you do with the data. The socket will
not know where the data is coming from until you actually do the
ReceiveFrom. At that point you will have to a buffer to read into.

3) With TCP I always called "Receive" exactly once each time the
OnReceive virtual function was called. For UDP I am wondering. I may
have data available for multiple IPs. Correct? Do I need to call
ReceiveFrom multiple times?
No. But you do need to make sure that the socket is serviced in a
timely fashion. I would suggest setting up the socket in a separate
user interface thread. This thread should do nothing more than
service the socket. OnReceive should also be very light weight.
(Just read the datagram and post a message to a window in the main
thread.)


4) I know I will be receiving data from three IPs. Once from each of
three NIC connections. I want my code to be general purpose and
handle any number of connections. QUESTION: How do you suggest I
maintain the multiple buffers that I will need? Should I use an STL
deque or an STL map, or what?
Again, this is a matter of what you end up doing with the data. The
socket handler itself doesn't need to know much about the messages.
It can forward them to the main thread which can process them as needed.

The main thread's handling could make use of a map or vector. I don't
see any advantage of using a deque.

5) I'm looking at other CAsyncSocket virtual methods. OnConnect. This
virtual function is called when a connection attempt is completed. I
assume with UDP that I won't get any OnConnect calls because with UDP
there is no concept of connection. Correct? The same would apply for
OnClose. Correct?

I believe you're correct.

Steve

Thank you for your time.

Today our customer gave us a document that implies that each of the
three closed networks are identical in subnet and IP assignments. We are
unable to confirm since a key person at the customer is out of the
office until late next week.

This means that my three network connections would each talk to a
distinct separate network but they would have identical IP subnets.
This won't work because when I call ReceiveFrom I will always get the
same IP and I won't be able to distinguish which partial packet I
receive on one ReceiveFrom call belongs to what other partial packet I
will receive a split second later on another ReceiveFrom call. Is this
correct?

The customer will not change the IP subnets.

Is the best way to solve this to use three servers one to talk with each
closed network?

Our customer tells us that they have a separate third party system that
uses three servers to talk with the three networks. These servers are
receiving the same UDP data that we need. The customer wants to know if
we can use these servers for our software. With UDP, can two
applications on the same server open the same UDP port and both receive
the same data?

You can not have more than one socket open to a port. The port is
identified by a protocol (UDP), IP and port.


The customer has also asked about using one server with multiple NICs
that runs virtual private server software. We have no experience. Could
we run three private servers on one machine with 1 network card
dedicated to each server. Can you do this? We would then run three
copies of my software? Would this work?

Another option we have discussed is putting a router between our server
and one of the closed networks. We would set the router to translate the
IP address to something different. The UDP data from one closed network
would pass through the router to our software. To our software it would
appear to come from a different IP subnet. Would this work?

Do you have any other ideas?


Thank you again for your time.


You have to be able to make the translation from MAC address to IP
address. A router may be able to do this for you. I have no experience
with this. You might have better luck on one of the network newgroups.

I don't know of any way normal application level software play games of
this sort.


IMPORTANT
Be aware of is the router is free to drop any UDP packet on a whim with
no notice.

Steve
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Very strange behavior of SQLServer with connection from CGI
    ... this is not a default SQL instance. ... SQL clients use a UDP ... connection to port 1434 to resolve port numbers for named instances. ... You can use the SQL Server Network utility to lock ...
    (microsoft.public.sqlserver.connect)
  • Re: Very strange behavior of SQLServer with connection from CGI
    ... this is not a default SQL instance. ... SQL clients use a UDP ... connection to port 1434 to resolve port numbers for named instances. ... You can use the SQL Server Network utility to lock ...
    (microsoft.public.sqlserver.clustering)
  • Re: Very strange behavior of SQLServer with connection from CGI
    ... this is not a default SQL instance. ... SQL clients use a UDP ... connection to port 1434 to resolve port numbers for named instances. ... You can use the SQL Server Network utility to lock ...
    (microsoft.public.sqlserver.security)
  • Re: Multiple closed networks and UDP. Please help me.
    ... Each of the three computers will be in its own closed network. ... I have worked with TCP many times, but never UDP. ... When I open a socket to receive one UDP socket stream do I ... I believe that the TCP connection will be assigned based on the IP address. ...
    (microsoft.public.vc.mfc)
  • Re: DC, RRAS and Multiple NICs
    ... > Site to Site link if you will not be doing any file and printer sharing ... >> Private Network Connection, but in the process of putting this connection ... >> managing a flat topology network across a 512K link. ... >> both Subnets at the same time? ...
    (microsoft.public.windows.server.networking)