• Advertisement

Archived

This topic is now archived and is closed to further replies.

Simple socket question...

This topic is 5154 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When using sockets with windows app programs would it be best to se the windows message and the lparm for getting the info or just use recv() or do they have their own purpose? Thanks. - Newb Programmer: Geek++

Share this post


Link to post
Share on other sites
Advertisement
Uhh, getting what you pass
So lets say I do a...

send(s, "Hi", sizeof("Hi"), 0);

On my client shold I use

recv(s, string, sizeof(string), 0);

or use the windows message (I forget what it is) which I beleive sends "Hi" as the lparm

That clearer? *brand new to this stuff*
I could also be reading these tutorial code parts wrong...

- Newb Programmer: Geek++

Share this post


Link to post
Share on other sites
Unless you''re using some completely alien sockets library, there isn''t a windows message that has the data sent as the lParam. You need to use recv() (or one of it''s sibling functions) in order to get data from the socket.

Share this post


Link to post
Share on other sites
Hrm, Seems I read it worng


case WM_SOCKET:
{
if (WSAGETSELECTERROR(lparam))
{ // error!

sprintf (txtbuffer,"Error2: %d",WSAGetLastError());
MessageBox (main_window_handle,txtbuffer,"Error",MB_OK);
PostQuitMessage (0);
running = false;
return 0;
}
switch (WSAGETSELECTEVENT(lparam))
{
case FD_READ:
{
char buffer[2];
recv (s,buffer,2,0);

switch (GameState)
{
case GS_TITLE:
{
if (buffer[0]==RPSS_NUMOFUSERS)
GameState = GS_WAITFORPLAYER;
} break;
case GS_WAITFORPLAYER:
{
if (buffer[0]==RPSS_STARTGAME)
{
p1 = 0; // reset scores

p2 = 0;
which_quad = 1; // set to rock for next screen

receivedpacket = false;
GameState = GS_WAITFORINPUT;
}
} break;
case GS_WAITFORINPUT:
{
switch (buffer[0])
{
case RPSS_ROCK:
{
choicep2 = 1;
} break;
case RPSS_PAPER:
{
choicep2 = 2;
} break;
case RPSS_SCISSOR:
{
choicep2 = 3;
} break;
default:
{ // error

PostQuitMessage (0);
running = false;
return 0;
}
}
receivedpacket = true;
}
}
} break;
case FD_CLOSE:
{ // opponent quit

sprintf (txtbuffer,"%c%d",RPSS_QUIT,0);
send (s,txtbuffer,2,0); // tell server that we quit

shutdown (s,SD_SEND);
closesocket (s);
PostQuitMessage (0);
running = false;
return 0;
} break;
}
} break;


I guess I''ll just ask if this is the best way to receive? I know people don''t like using the WM key events because of speed and such, any similar preferences with sockets?


- Newb Programmer: Geek++

Share this post


Link to post
Share on other sites

  • Advertisement