Networking Forums

Networking Forums > Computer Networking > Linux Networking > Client to connect to a chat server

Reply
Thread Tools Display Modes

Client to connect to a chat server

 
 
Nikolaj
Guest
Posts: n/a

 
      10-29-2006, 12:55 PM
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

 
Reply With Quote
 
 
 
 
Mihai Osian
Guest
Posts: n/a

 
      10-30-2006, 06:22 PM
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
 
Reply With Quote
 
Nikolaj
Guest
Posts: n/a

 
      10-31-2006, 10:04 AM
Thank you very much Mihai!
I was thinking that the solution was somenthing like using select but
I wasn't certain.
If I have a program that read from a keyboard, it reads from a file
stdin, and when it reads from a server, it reads from a socket. Both of
them have a file descriptor.
So, I can use select to see in which file there are some activities,
I can control the file descriptor and I can read only from the file who
has some data.

Thank you again.

Nikolaj

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Client cannot connect to VPN server - others can Thomas D. Windows Networking 2 01-27-2007 10:47 PM
ssh client gets to server, but doesn't connect...? /usr/ceo Linux Networking 4 10-06-2006 09:46 PM
Connect client to server Rajani Windows Networking 4 01-09-2006 09:55 PM
Can't connect to 2k3 server from mac osx smb client Ben Windows Networking 2 04-13-2004 11:48 PM
Cannot connect Linux FTP server with Win client Ivan Linux Networking 1 10-11-2003 06:37 PM



1 2 3 4 5 6 7 8 9 10 11