Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 27th, 2005, 11:26 AM   #51
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
What compiler are you using? What error messages do you get?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Aug 27th, 2005, 12:09 PM   #52
L7Sqr
Hobbyist Programmer
 
Join Date: Jun 2005
Location: here
Posts: 114
Rep Power: 0 L7Sqr is an unknown quantity at this point
Quote:
could i use select() in my IM instead of threads
I've already detailed what select does....
And, as I'm sure you've taken the time to research threads, you understand their functionality. What do you think?

A thread, simply put, allows you code to execute in a non-linear way. It allows for the appearence of simultaneous execution of two seperate sections of code. So, in your case, you could be executing a loop that is waiting for a message and one that sends a message (when appropriate) at the 'same time'.

However, you now must deal with shared variables, mutexes and race conditions (among other things).

You can do what you want (well, acheive the same result) without using threads. It wont be because of how you use select. Your design details what is required. If you wish to avoid threads, a redesign may be in order.

And, as an aside, I would suggest you NOT use the timeout feature of select. 30 seconds worth of non-interaction isn't unheard of. You don't (at least I don't) want an error in that case. If I'm not mistaken, a chat window may stay open indefinately, if the user so desires.
__________________
"...and though our kids are blessed their parents let them shoulder all the blame."
- The Quiet Things That No One Ever Knows [BrandNew]
L7Sqr is offline   Reply With Quote
Old Aug 27th, 2005, 1:38 PM   #53
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 249
Rep Power: 4 Brent is on a distinguished road
i have researched threads, and decided that select would be a better choice to use because of the complexity of threads. what do you mean by design details what is required?
Brent is offline   Reply With Quote
Old Aug 29th, 2005, 11:37 AM   #54
L7Sqr
Hobbyist Programmer
 
Join Date: Jun 2005
Location: here
Posts: 114
Rep Power: 0 L7Sqr is an unknown quantity at this point
What I mean is, what you design dictates what you must create.
If you decide that threads will be too much to overcome for your project and your original design was best implemented with threads, you have two choices: Redesign --or-- muddle through painfully. I was suggesting that the former may be in order here.
__________________
"...and though our kids are blessed their parents let them shoulder all the blame."
- The Quiet Things That No One Ever Knows [BrandNew]
L7Sqr is offline   Reply With Quote
Old Aug 29th, 2005, 7:11 PM   #55
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 249
Rep Power: 4 Brent is on a distinguished road
i think ill try threads...is there a certain threads class that i use?
Brent is offline   Reply With Quote
Old Aug 31st, 2005, 6:26 AM   #56
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 314
Rep Power: 4 mackenga is on a distinguished road
I think what messes with people with select() is the slightly itchy way you have to specify the file descriptors to watch. It's not really as tough as it looks, but you do have other options.

One 'soft option' which is OK for simple programs is to poll using non-blocking IO. You can use blocking IO for the send(), but investigate setsockopt() and set recv() to non-blocking; in cases where there's nothing to read you'll get an error return from recv(). Just make sure you don't end up thrashing, repeatedly polling without any delay between checks.

Using signal-driven IO is also often easier than using select() where your application is nice and simple. Not sure how that translates to Windows, though; I suspect it doesn't.

Quite early on, MJordan2nd suggested threads ... weirdly, this is actually one of the easiest and most intuitive methods. Threads are separate lightweight processes within a single process, and allow your program to do more than one thing at a time. The way you can do this sort of chat program with threads is just create one that always reads the socket and prints everything it receives, and another that always reads the terminal and writes whatever it finds to the socket. The two of them don't need to interact (though you can occasionally get in a bit of a mess on the terminal if you don't do any synchronisation between the two), so this is dead easy; when one is blocking on recv() the other is still free to read from the user.

You do have to learn how to use threads to do it this way, but that'll be useful down the line anyway so I recommend it.
mackenga is offline   Reply With Quote
Old Aug 31st, 2005, 12:18 PM   #57
Brent
Highly Adaptive Penguin
 
Brent's Avatar
 
Join Date: May 2005
Location: United States
Posts: 249
Rep Power: 4 Brent is on a distinguished road
thanks...i dont understand how to create threads. how do you make programs do multiple process's at a time?
Brent is offline   Reply With Quote
Old Aug 31st, 2005, 12:57 PM   #58
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
You really should be asking Google these questions. The answers are out there, and succint.
Cerulean is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:47 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC