Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 1 month ago.
looking for a simple TCP socket
hi there,
im a beginner in C programming.
Have somebody a example program for a simple TCP Socket server?
i bought the NET IO App in Android Play store.
The App comunicate with the mbed over the ethernet, but the App need a TCP socket.
my idea is a simple Code
if(incoming_data=="set somthing on") { do_something(); }
for switch a digital output.
Can somebody help me ?
thanks you very much!!!
1 Answer
11 years, 1 month ago.
The TCPSocketServer page is very useful:
http://mbed.org/handbook/Socket
Modify the TCP Echo server to do something when you receive data, rather than echoing it back.
I have a setup that does just that. I opted for the mbed to be a client which connects to a windows based server. This gives scalability if your mbed network gets bigger. The issues I've run into is not with the TCP data transfer, but the parsing of text messages. It takes quite some thinking to get it right. You should decide on an 'end of transfer' string that either side can detect and act on. Furthermore the sending side needs to know if the message has been received - and received correctly, and if not, what to do.
Request a resend? To what client? How long to wait? Should I buffer later data while waiting for the resend? Do I need transfer ID's? The list goes on.
Of course this depends on your intended application and how important every transaction is.
I rely on the old EthernetNetIf library which is known for low transfer rate but high reliability. The newfangled ethernet libraries can achieve transfer rates hundreds or thousands of times faster, but I've read reports of it crashing at the least wanted point, so for my specific app I'm sticking with the old one. At least until the higher rates are required.
These are excerpts from my heavily reduced working code:
Sort of a double post :/
posted by Hugo Harming 30 Oct 2013