tcp/ip

Dec 28, 2004 2 Replies

Hi there, I'm working with socket programming to let an embedded linux system (TS-7200 board) deal with a windows-based client. After calling "socket", "bind" and "listen" I need to call "accept" to establish the connection between client and server. How can I accept a connection in non blocking mode? With fnctl I can set this mode for my own socket file descriptor and it works with the listen command, but how can I let my program work unblocked? I need to make differnt things while waiting for data to be ready to read on the ethernet. If data can come in asyncronously from different sources (ethernet, rs-485, rs-232) how can I determine which one to choose and when? Thanks, Marco


Some of many options:

You can use select() to wait on one of several resources.

You can create multiple processes by using fork() and communicate between them e.g. with system V message queues or sockets.

You can create multiple threads using the posix thread library. Here all threads can share the data memory, so that you don't need to transfer data from one to another. Posix threads are especially interesting when using Linux 2.6.x as the thread performance has been improved greatly (with 2.4 threads were justs processes that share memory pages).

-Michael

Use select on the listen socket and then accept. Beej's famous guide shows this in detail:

formatting link

Best regards,

Bernhard Roessmann Don't Fear The Penguins!

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required