Click here to Skip to main content
15,907,396 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionVery Basic socket programming, Winsock! Newb help.. Pin
Beaon12-Sep-07 7:55
Beaon12-Sep-07 7:55 
AnswerRe: Very Basic socket programming, Winsock! Newb help.. Pin
Mark Salsbery12-Sep-07 8:06
Mark Salsbery12-Sep-07 8:06 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Beaon13-Sep-07 6:03
Beaon13-Sep-07 6:03 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Mark Salsbery13-Sep-07 6:15
Mark Salsbery13-Sep-07 6:15 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Beaon13-Sep-07 6:59
Beaon13-Sep-07 6:59 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Mark Salsbery13-Sep-07 7:04
Mark Salsbery13-Sep-07 7:04 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Beaon14-Sep-07 3:43
Beaon14-Sep-07 3:43 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Mark Salsbery14-Sep-07 6:04
Mark Salsbery14-Sep-07 6:04 
TCP is indeed reliable.  The thing is, it's a stream oriented protocol, so it
only understands bytes.  You could send 32KB-sized "packets" but the
underlying protocol may split that however it needs to for delivery.  TCP
guarantees you'll receive all the bytes sent, in order, but they won't necessarily
come in one recv() call.  That's why you need to do whatever it takes so the send
and receive ends stay in sync.  It's essentially a protocol on top of TCP.

Make sense?

For the UI, yes, an asynchronous socket is ideal.  Event-driven socket communication
is very efficient.

On the server side, you use the socket returned by accept().  That's the socket
connected to the client.
On the client side, you already have the socket - the one you connected to the server with.

I recommend reading the docs for WSAAsyncSelect VERY carefully.

The easiest way to get started is to request notifications for FD_READ and FD_CLOSE.
Then your window will receive the message you specify whenever there's data to be "recv()"'d
from the socket, and when the connection is closed.

On any given FD_READ notification, you can read as many bytes as you need to.  If all the bytes
you're expecting aren't there yet, you need to keep track of that for when you get the next FD_READ. 
If more bytes than you recv() are available, you're guaranteed to get another notification.
Again....read the docs carefully Smile | :)

Beaon wrote:
also won't the sender side have to send those windows messages as well?


No.  Both ends of the connection handle everything themselves.  Basically, just
sending and receiving bytes.  The notifications are available so you don't have to
sit in a loop wasting CPU cycles waiting for data. 

Once a connection is established, there's no difference between the client and the server ends.
You could actually use identical code on both ends.

Mark



Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Beaon14-Sep-07 6:20
Beaon14-Sep-07 6:20 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Beaon14-Sep-07 8:22
Beaon14-Sep-07 8:22 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Mark Salsbery14-Sep-07 12:39
Mark Salsbery14-Sep-07 12:39 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Beaon17-Sep-07 5:49
Beaon17-Sep-07 5:49 
AnswerRe: Very Basic socket programming, Winsock! Newb help.. Pin
Beaon17-Sep-07 9:21
Beaon17-Sep-07 9:21 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Mark Salsbery17-Sep-07 9:43
Mark Salsbery17-Sep-07 9:43 
QuestionDisplaying text in non-english language on console [modified] Pin
ComplexLifeForm12-Sep-07 7:02
ComplexLifeForm12-Sep-07 7:02 
AnswerRe: Displaying text in non-english language on console Pin
Matthew Faithfull12-Sep-07 8:21
Matthew Faithfull12-Sep-07 8:21 
QuestionExiting process Pin
koumodaki12-Sep-07 6:16
koumodaki12-Sep-07 6:16 
AnswerRe: Exiting process Pin
Hamid_RT12-Sep-07 6:44
Hamid_RT12-Sep-07 6:44 
AnswerRe: Exiting process Pin
Mark Salsbery12-Sep-07 6:45
Mark Salsbery12-Sep-07 6:45 
AnswerRe: Exiting process Pin
aks.12-Sep-07 15:49
aks.12-Sep-07 15:49 
Questionproblem with multithreading and wrapper-class object Pin
kyer12-Sep-07 4:53
kyer12-Sep-07 4:53 
AnswerRe: problem with multithreading and wrapper-class object Pin
Randor 12-Sep-07 4:59
professional Randor 12-Sep-07 4:59 
GeneralRe: problem with multithreading and wrapper-class object Pin
kyer12-Sep-07 5:30
kyer12-Sep-07 5:30 
GeneralRe: problem with multithreading and wrapper-class object Pin
Randor 12-Sep-07 6:07
professional Randor 12-Sep-07 6:07 
GeneralRe: problem with multithreading and wrapper-class object Pin
kyer12-Sep-07 8:23
kyer12-Sep-07 8:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.