Re: Multiple closed networks and UDP. Please help me.
- From: TomChapman <TomChapman12@xxxxxxxxx>
- Date: Tue, 27 Oct 2009 20:46:05 -0500
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?
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?
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?
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?
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?
.
- Follow-Ups:
- Re: Multiple closed networks and UDP. Please help me.
- From: Joseph M . Newcomer
- Re: Multiple closed networks and UDP. Please help me.
- From: Stephen Myers
- Re: Multiple closed networks and UDP. Please help me.
- From: TomChapman
- Re: Multiple closed networks and UDP. Please help me.
- References:
- Multiple closed networks and UDP. Please help me.
- From: TomChapman
- Re: Multiple closed networks and UDP. Please help me.
- From: Stephen Myers
- Multiple closed networks and UDP. Please help me.
- Prev by Date: Re: [OT] Intel Compilers vs. Microsoft Compilers Optimization/Performance on Math Calculations,....
- Next by Date: Re: Multiple closed networks and UDP. Please help me.
- Previous by thread: Re: Multiple closed networks and UDP. Please help me.
- Next by thread: Re: Multiple closed networks and UDP. Please help me.
- Index(es):
Relevant Pages
|