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 question

Status
Not open for further replies.

Valius

Programmer
Oct 20, 2000
174
US
This may be a stupid question, but I just want a yes or no answer. Can data be sent AND received at the same time on the same socket? I guess I'm asking if a socket has Full-Duplex capabilities. Thanks in advance!

Niky Williams
NTS Marketing
Niky.Williams@NTSMarketing.com
 
Yes, in but in different threads. John Fill
1c.bmp


ivfmd@mail.md
 
okay, another quick question. Would the best way to go about this whole sockets thing is derive a class from the CSockets class and override the OnSend() and OnReceive() member functions? Thanks for the input!

Niky Williams
NTS Marketing
Niky.Williams@NTSMarketing.com
 
Hi,

You don't need to derive a class but that's up to you. I would suggest you have a full understanding of sockets (blocking, synchronous, asychronous) before you go on. Because of your initial question I'm assuming you don't have a very good understanding of sockets and you'll end up spending lots of time trying to figure out what's going on with your code. Trouble shooting sockets code isn't very easy even when you know what you're doing.

But if you wish to proceed... you can do this many ways.

One: Create two threads. One to receive and one to send.

Two: Use one thread and check receive and send in the same thread. This means you'll need to make sure your socket is non blocking and check for WSAWOULDBLOCK when you receive. You'll also need to set a flag when you've put data in the buffer to send or have another way to signal that data is ready to send.

Three: Create event driven sockets.

Have fun,

Brother C
 
Hmm..I tried makeing two seperate threads, one for receiving and one for sending. I have a fairly basic understanding of how sockets work. The problem I was having was that my program needed to know when another computer had sent some data...this is why I was thinking about overriding the OnReceive() function. What was happening was that I was getting to a point when both programs were waiting for data and when my client tried to send some data, the socket was already listening for data and when I tried to send out data on the socket at the same time it was listening for data I was getting an error. Before I scrapped the program and started over I tried to kill the blocking socket so that it was free to send. I have a lot to learn in this subject. Thanks for the info and your time.

Niky Williams
NTS Marketing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top