3

My Scenario is:

There are two pieces of software running on two different machines, one as a server and one as a client. They both use same ports for communicating to each other on UDP level. ( due to the client hardware it's not possible to set the communication on TCP level ( limited memory )). This scenario works already for like 15 years right now.

Now I want to make an emulator for this client, so that I won't have to use the client ( as it needs to be reconfigured everytime I need to debug and to do trouble shooting ). And it's not at the same location as where I'm at.

The thing I did was made a simple client application with a listenerport and a senderport ( same as the sever ) on a virtual network card ( created with de devcon utility )

Now when I run the client I get a SocketException:"Only one usage of each socket address (protocol/network address/port) is normally permitted" ( This is the first thing what happens when I start the client )

This happens at the line where I create the listener : UdpClient listener = new UdpClient(listenPort);

In the osi model there is first the network layer(ip addres) and then the port numbers ( with the TCP/UDP layer )..

7   Application     Process Application     
6   Presentation
5   Session
4   Transport       Host to host          TCP, UDP  Packets
3   Network         Internet              IP, ICMP  Frames
2   Data Link       Network Access        ARP       Bits
1   Physical 

The client is not listening on the same networkcard as the server is ( but they are both running on the same computer though ).

The thing I don't get is why this message? Might it be that's it's not possible to create a virtual network card and use the same ports on the same computer? ( As I want to run the client and server on the same computer )

[edit] Scenario of the setup

I was just wondering that it might not be possible just as for the reason that it's using one list of porst for all the network cards and therefore it's already being used. Then my question is:"how to make a second list of ports to listen too ( as it's different networkcard in the same computer?"

It's almost the same as VirtualBox or VirtualPC makes a new virtual network card. When they are created it's possible to listen on the same port ( although it's a virtualmachine ) but still is the same hardware. Then rises the question on how did they do it?

[/edit]

DForce
  • 31
  • 1
  • 5
  • Is there a real need to let the client use the same port as the server? – lboshuizen Oct 10 '12 at 09:56
  • Yes, the existing scenario works like this ( for 1,5 decade right now ) and to change this ... well that's just not an option for me, as the whole infrastructure of our machine depends on it. – DForce Oct 10 '12 at 10:00
  • Are you properly binding the local socket to the right network card? Your server to the main one, and the test client to the fake card? – Matthew Kennedy Oct 10 '12 at 10:08
  • 1
    @MatthewKennedy The lines of code I'm using `UdpClient listener = new UdpClient(listenPort); IPEndPoint groupEP = new IPEndPoint(IPAddress.Parse("192.168.0.3"), listenPort);`. As It already gives an error at the first line. Did it the other way around , but then still at the second line. – DForce Oct 10 '12 at 10:13
  • Did you try another port for the client? As far as I know should for the server not be a real issue what the portnumber is on the client. – lboshuizen Oct 10 '12 at 10:21
  • @lboshuizen Yes that will work, but then I don't get the connection I need ;) I've drawn a little schema of how the situation needs to be : ![Image](http://www.uploadarchief.net/files/download/udp-client-server-setup.png). – DForce Oct 10 '12 at 10:37
  • @lboshuizen: I know that it doesn't matter from which port it is being send, as long as it reaches the listener port. I think that when opening a new UdpClient ( on the same computer ) there is a list somewhere that is containing the opened ports on that computer for all the network cards and not for each network card. Might that be the reason it can't set the same port on the same computer? – DForce Oct 10 '12 at 10:52
  • So still no solution here, i've runned the application on a virtual machine on the same computer, and that works. But that's not the scenario I need. Still the question stands. – DForce Oct 16 '12 at 08:56

3 Answers3

0
  1. You could run/debug inside a virtual machine.
  2. You can buy a cheapo (

As far as adding a second, virtual network adapter, I have never seen a program that fakes another card on your machine.

Matthew Kennedy
  • 616
  • 4
  • 19
  • Creating a virtual machine is a last resort option as I don't want to install a virtual machine with each customer that has our machine ( like all over the world ), it just needs to be a solely program that runs next to the server on the same client. Thus my question still stands:"Is it possible with a virtual network card to open up the same ports on udp level on the same pc?" – DForce Oct 10 '12 at 10:03
  • Ah, so you need to emulate on every production instance, not your development machine. – Matthew Kennedy Oct 10 '12 at 10:06
  • Yes, to go deeper into the scenario:"At the customers place there is a robot that's connected to a pc where is the controlling software, as I don't want to reconfigure that pc I just want to set the Robot to listen to the emulator where I can easily adjust values and do debugging without touching the customers computer ( as reconfiguring can be a teadious task ( just before you'd might ask:"no it's not possible to create a backup - tinker with the configuration - and copy the backup back ;) )) – DForce Oct 10 '12 at 10:11
0

Specify 0 as the portnumber when creating a new UdpClient()

var clt = new UdpClient(0);

According to the docs at MSDN the underlying provider assigns a free portnumber without a conflict.

Your software is an emulator to test the robot. To me there's no need to follow the specs of the clienthardware for that purpose.

lboshuizen
  • 2,746
  • 17
  • 20
  • Well actually there is , because the RoboSoftware is sending to port 2053 and it needs to get a reply to the same port ( see the attached picture in the post above ). And that both pieces of softwar are on the same computer. This is what's bothering me. – DForce Oct 11 '12 at 12:01
0

I've solved my problem! The theory of my idea above works.

What I found out is that my predecessor has set a UdpPortListener on ALL available network cards that are in the current computer....

 IPEndPoint(IPAddress.Any, receivePort);

I've set this at the Networkcard I want to listen to and it works! Conclusion here is , never make assumptions on how someone implemented code ( even how it says on paper ) and always try to do some "reverse-engineering" on how things are actually handled!

Thank you all for helping me out here!

DForce
  • 31
  • 1
  • 5