views:

900

answers:

6

I have a need to write a quick and dirty application to write some data over an ethernet connection to a remote machine. The remote machine is sitting waiting for data, and I just want to blat some data at it to test the connection and bandwidth etc.

I'd like to be able to, say, send a known pattern of data (simple counting or repeating pattern) over the connection and be able to increase the bandwidth by x2, x10, x100 etc.

No need for handshaking, CRC, specific data format, framing etc. just plain old data.

Please... no third party libraries, just C++ (or C, or python)

A: 

You can use Sockets.

Here is some basic tutorial.

Vinay
+3  A: 

I can recommend Beej's Guide to Network Programming. Helped me to understand all that network mumbo-jumbo.

However, if you need something really quick, why not use .NET? That has pretty nice classes for doing things like this. You could write your data in 10 lines.

P.S. Don't get thrown off by the fact that this is written for *nix. Winsock has all exactly the same functions.

Vilx-
thanks i'll look into that link...
Krakkos
They are not exactly the same. Im not trying to nitpick, but I have trusted my friend when he told me that before I had to port my application from Windows to Linux. I wanted to strangle him as soon as I have seen all the differences. It took me ~2 hours to port the whole application.
Patrick Daryll Glandien
i think Vilx meant that it would be easy to understand for both Windows and Linux, not directly portable.... btw, 2hours to port? nice going ;)
Krakkos
+1  A: 

When you say "IP:Port" then you must mean you need something higher layer than just an ethernet frame. You should read up on TCP/UDP/IP programming. I think the best resource online for this is Beej's Guide.. This is targeted toward berkeley or windows sockets.

Python sockets tutorial here.

Or just use teh googles and search for "socket programming in [language]".

Doug T.
umm... I didn't purposely mean "higher layer".. all I know is I have a machine at the other end of an ethernet cable with an IP address :)Thanks for the links though.
Krakkos
"higher layer" is very relative. I mean higher than OSI layer 2. See here for more info. http://en.wikipedia.org/wiki/OSI_model
Doug T.
A: 

This tutorial seems to cover what you want:

http://www.amk.ca/python/howto/sockets/

anon
A: 

Sounds like you want to be able to saturate the link for testing purposes without regard to whether the receiver can accept all the data. So, you will not want to use TCP since it is acknowledged, and flow controlled to avoid overrunning the receiver.

Probably easiest to go with UDP, although you could also consider a raw socket if you really want to write Ethernet frames directly (i.e. if you need to send data without IP/UDP headers, just raw Ethernet frames. In this case you'll need the destination MAC address to put in the Ethernet frame so it goes to the right place).

Regarding framing and CRC: Ethernet hardware will frame the packets and generate/check CRCs.

Edit: It might help if you could state what you are trying to achieve. Is it to test the speed of the Ethernet links/switches, or to see how fast the sending and receiving CPUs can exchange data? (It's likely that you can send data faster over Ethernet than the receiving CPU can handle it, although that does depend on the speed of the Ethernet and CPUs, as well as what OS the CPU is running, how busy it is, how it's network stack is tuned, etc..).

Dave
ok, not sure if I need TCP or UDP... and really the network loading would be a nice to have rather than the basic need to send some data...I think UDP may well be the wayt o go, as I will have the need to send unacknowledged data.
Krakkos
+3  A: 

If you can use netcat:

echo "BEEFCAKE" | nc remote.host port
Eddy
lookup iperf if you're just looking to test bandwidth
Eddy
i'll try that... would definitely be the most succunct method :)
Krakkos
Actually, i think nc needs to be started on both sides of the connection.I already have a receiver sitting there waiting for data, I just need to send data out...
Krakkos
You should be able to send data to your existing server with nc
Sam Hoice