C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 5th, 2005, 05:02 AM
vuongx vuongx is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 1 vuongx User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
multithread server

i write a multi client - server program in MFC
I use multithreading with socket and ca'nt figure it out.

my program create two class base on CSocket : CListenSocket and CClientSocket .

i listen myListenSocket.
when a client connect to server
i accept it.
....
myListenSocket->Accept(*myClientSocket)
AfxBeginThread(CClientThread,???)
...
UINT(CCLientThread,LPVOID para)
{}
...
i dont' know how to put this pointer myClientSocket to thread function...
any help...

Reply With Quote
  #2  
Old January 5th, 2005, 10:26 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is online now
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,249 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 5 Days 17 h 27 m 51 sec
Reputation Power: 1985
Covered in Multithreading 101.

You have a function that is run as a thread, CClientThread in your example.

It has a pre-defined parameter list; ie, that parameter list is predefined by the compiler and the declaration of your CClientThread function must comform to that definition.

The parameter of interest is a void pointer. That's the one that you use.

Take the address of the socket and cast it as a void pointer. Within CClientThread, cast its void pointer argument as a pointer to a socket and then use it.

If you have multiple parameters you want to pass into a thread, then declare a struct to contain all those parameters, create a struct variable and populate it, then pass a pointer to that struct variable cast as a void pointer.

Your help files should have examples of this. Yes, I know that it is not easy to look up specific info in VC++6 help. And if you're stuck with .NET, I found that that is not much better.


Question:
myListenSocket->Accept(*myClientSocket)
Is myClientSocket a pointer? If Accept() is written to return the new client socket through the parameter list, then why are you dereferencing that pointer?

Possibility: Is myClientSocket a socket type and you are trying to pass a pointer to it? In that case you need to use the address operator, &; ie:
myListenSocket->Accept(&myClientSocket);

Last edited by dwise1_aol : January 5th, 2005 at 10:38 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > multithread server

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap