Monday, 6 August 2012

Raspberry Pi - C Programming and TCP/IP

I've been meaning to get into a bit more C programming lately as my new job is embedded C programming. I've also got quite an interest in networking and associated protocols.
I thought that it would be a great idea to cut my teeth on TCP/IP using my Raspberry Pi and my Desktop computer.

Currently my network set up is as such:

INTERNET > ROUTER > Wireless
                  > SWITCH > UNMANAGED SWITCH
                                     > Raspberry Pi
                                     > My Desktop

Hopefully you can understand that. Basically I've got my desktop and Raspberry Pi connect via Ethernet and an unmanaged switch.

I've learnt C for about 2 years now, so I'd say I'm al right with it, just a little rusty as I haven't used it in about 6 months (been learning Java). All I needed to look up programming wise was either a book or tutorial using Cs TCP/IP libraries and some examples.

I had a read of some websites, however found that the example code on this website was the most useful for just getting the basic idea of how it works.

So I set up the copied, compiled and ran the TCPEchoServer.c on my desktop. I had to include the DieWithError.c and HandleTCPClient.c files using two #include "..." s

I compiled them using the command gcc -Wall -o echoServer TCPEchoServer.c 

Then I tested them just locally using to locall loopback address (127.0.0.1) and my LAN IP address (10.1.1.10):



I had to install gcc on the Raspberry Pi using:

pacman -S gcc

After I copied and compiled the TCPEchoClient.c file I checked I had connectivity by sshing into the Raspberry Pi then running the client and pointing it toward my desktop computer.


Success!