Teen Programmers Unite  
 

 

Return to forum top

Linux Sockets question (c)

Posted by woodstock [send private reply] at February 03, 2002, 01:53:23 AM

I'm attempting to do some socket programming in C.
To get my feet wet, I want to create a simple command-line program that will allow two people to chat back and forth. However, I do not know of a way to allow the user to enter and send data as the program listens for incoming connections.

Is there any way to do this? (I assume that there is, otherwise gaim and licq would not run as one process, but rather as a server and a client)

Am I asking a stupid question due to sleep deprivation? Any help would be much appreciated.

Thanks!

woodstock

Posted by Psion [send private reply] at February 03, 2002, 09:09:52 AM

Using select() and your own input routines you could manage this in a single thread/process, but it would probably be easiest to have separate sending/receiving threads/processes.

Posted by unknown_lamer [send private reply] at February 04, 2002, 02:19:21 PM

You can either use POSIX Threads or select. DO NOT USE POSIX THREADS. That leaves select. Threads introduce a lot of syncronization bugs (like the one I am wrestling with in my "Music Player" where the UI thread checks to see if the mutex is locked too soon...)

Posted by Psion [send private reply] at February 05, 2002, 01:49:16 PM

Those "synchronization bugs" are not inherent in the API or implementation. They come from your apparently insufficient level of knowledge about concurrent programming. A similar lack of knowledge would be the only reason to flat out remove pthreads from the realm of possibility.

Posted by unknown_lamer [send private reply] at February 06, 2002, 10:59:35 AM

I know. But, if he is having trouble with sockets, adding threads to the mix can only make it much, much worse. (I also appear to have fixed my threading bug...I just had to lock the mutex in the main thread before starting the new thread).

Posted by woodstock [send private reply] at February 10, 2002, 01:34:05 AM

Thanks for your advice, guys.


It's not that I'm necessarily having trouble with sockets, it's just that I did not know if there was a way to listen for a connection/receive data while allowing the user to input/send data.

Not trying to take a shortcut really, I just doni't want to sift through a load of UI code of something like Licq, etc. to find the meaty socket part :)

Thanks again.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.