[gameprogrammer] NET2 and socket use

Hi All

I am (for the third time :) ) writing a multiplayer, over the network,
snake game. Like lightcycle.
Anyways, thats not the point. Basically, I have been playing around with
the net2 examples tc.cpp and ts.cpp, seeing what sort of things I will
need to do when I implement the multiplayer portion of my game. I plan
to do the same playing with uc.cpp and us.cpp when I am satisfied I
understand the issues surrounding tcp.

Anyway, ts accepts connections on the port 6666, then goes on to wait
for events.
tc on the otherhand connects to port 6666 on localhost, and start
sending messages.
I modified ts to print the messages to the console.

If I wanted to send a message back, do I need to open another socket? Or
can I just use the one I got in the event?

---- code snippet ----
case NET2_TCPRECEIVEEVENT:
while (0 != (len = NET2_TCPRead(NET2_GetSocket(&ev), buf,sizeof(buf))))
{
printf("%s",buf); //Print out the message
memset (buf, 0, sizeof (buf));
sprintf (buf, "Reply\n"); // create the message to send
NET2_TCPSend (NET2_GetSocket(&ev), buf, sizeof (buf)); //send it and count it.
count += len;
}
break;
---- code snippet ----


In the client I added a case in the switch statement to match on
SDL_USEREVENT etc...

---- code snippet ----
while(1){
while (FE_PollEvent(&event)){
switch (event.type){
case SDL_USEREVENT:
switch(NET2_GetEventType(&event)){
case NET2_TCPRECEIVEEVENT:
while (0 != NET2_TCPRead(NET2_GetSocket(&event),buf, sizeof(buf))){
printf("%s",buf);
}
break;
}
break;
default:
break;
}
}
memset (buf, 0, sizeof (buf));
sprintf (buf, "A Message");
NET2_TCPSend (s, buf, sizeof (buf)); // send it and count it.
}


---- code snippet ----

Because I tried the above, and I dont think it worked. The program
compiled and ran fine, as if the memset, sprintf and NET2_TCPSend
functions were not there :) tc never spat out 'Reply', ts does spit out
'A Message'.

Have I misunderstood some fundmental idea or something?

Jake

--
Jacob Briggs
Systems Engineer
Core Technology
Ph: +64 (04) 499 1102

--

Named after its country of origin 'England', English is a little known dialect 
used by up to 1.5 billion non-Americans worldwide. Some interesting but 
obviously incorrect features of the language include:

- queues of people
- wonderful coloUrs
- the useful metal aluminIum
- the exotic herbs (h-urbs), basil (ba-zil) and oregano (o-re-gaa-no)
- specialiSed books called 'dictionaries' that tell you how to spell words 
correctly

Many people using this bizarre gutter speak also subscribe to the pagan belief 
that water freezes at 0 degrees and that distances should be measured in the 
forbidden mathematical system of base-10...



---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: