Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSocket help please 2

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
I'm experimenting with sockets by using the CSocket in MFC. This is what I would like to do, but not sure how. I've got my server and client programs to talk successfully, however, when the client is waiting on data from the server, it sticks there and the program doesn't go any further until the data is received (blocking socket? Someone correct me if I'm wrong). Another approach that I have seen is using the windows messaging to send a message to tell me the data has been received. So what I would like to do is start a thread everytime the client has successfully received data so that it is ready for the next string. My problem is with the thread. I have some varibles that I need to access in that thread that I have in my main program. Well, I can declare a global, but when I try and access it, it errors out. It seems like it SHOULD work. I'm guessing that when the thread exits, the variables get messed up somehow. I guess I just need some thoughts on how I can go about this. Maybe some tips from some of the Senior guys out there that have worked with this before and can give me some constructive criticism? Thanks in advance!

Niky Williams
NTS Marketing
Niky.Williams@NTSMarketing.com
 
what u can do is derive a class from CSocket and override the onRecieve() virtual funtion which will tell the socket when data is coming then u can use Recieve() fuction to recieve the data.so there is no need to wait when the data is going to come

CMySocket:public CSocket
{
// overide OnRecieve virutal funtion
void OnRecieve(int nErrorCode)
{
// call recieve here
Recive(..)
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top