Virtual Box can come in handy if you want to test basic client server code out on your desktop. This post will discuss a small udp client and server. The udp server will be a small c application designed to run on a linux guest machine. The udp client will be a python script running on a windows host. The configuration I used for testing this was a Windows 7 host with a Ubuntu 12.04 LTS guest.
Basic UDP Client Server
Here is a basic udp server in c This code compiled with one warning using gcc. The resulting executable listens on the port that is passed as a command line argument.
Note the file as written calls gethostbyaddr which failed in my environment.
Here is a basic udp client in python This script needs to have the HOST variable set to the ip address of the guest machine (use ifconfig to check the ip address of the guest) and PORT variable set to the port number you pass to the server on the command line.
Networking With Virtual Box
After starting the server on the guest, I ran the client script and immediately recieved the following error.
Bind failed. Error Code : 10049 Message The requested address is not valid in its context
By default Virtual Box guest machines are given one virtual ethernet interface configured to use NAT networking mode. Thus the error.
The Virtual Box networking documentation shows that host only networking is needed. To enable host only networking the guest machine will have to be powered down. Then a second ethernet adapter with host only networking can be added to the guest machine.
These slides showing virtual box host only networking might also be helpful to review.