Basic question about sockets

Hi -

I've written an app that, among other things, accepts a telnet connection (made via the "telnet" command from a terminal) and converses with it. I'd like to make this work so that only one client at a time can connect. Currently, when a second user tries to connect, the incoming messages get mixed up and lots of unpredictable results ensue.

Can someone point me in the right direction on how to lock out any subsequent connection attempts when someone already has a connection?

Thanks.

Oh, this is running SMX, not UNIX, but it has a very UNIX-like socket programming interface.

Not sure I understood:
Is it you want only one connection? meaning that all other are refused till disconnect (single user app.) ? Or is it you have problems dealing with concurrent access e.g. when 2 people try to connect at the same time (in sequence , no issue...)

We wish the program to be single-connection. The app is a controller for a modem, and multiple users with concurrent access to the modem settings is unacceptable.

Once a particular user has terminated his session, it's fine for someone else to start one.