Nikolaj wrote:
> Hi everybody,
> I have a program server that receive strings from many clients and
> then send this strings to all the clients connected to him. I connect
> to the server with Telnet.
> But if I want to write the program client I have a problem. I have to
> write code that read from keyboard a string and a code that read
> strings from the server (other clients), in this way a made a chat.
> But if I write this, the program stops when he has to read from the
> stdandard input (keyboard) and if there are data from the server he
> don't go receive them.
> Also if I write code that receive data from the server, if data isn't
> there, I'm wasting my time.
>
> How can I resolve this?
> Thank you very much.
>
> Nikolaj
>
What you are looking for is "select" and "non-blocking sockets". Go
here:
http://linoleum.leapster.org and under "network programming" you
will find some examples how to use it.
Hint: when you read from the console, you read from a default
file-descriptor called "stdin". You can use "select" with any file
descriptor (sockets are "descriptors", too).
Mihai