winsock: recieving
hi,
ive got udp client/server programs working, based on the stuff from http://www.hal-pc.org/~johnnie2/winsock.html and the code [linked] http://www.sockaddr.com/ExampleSourceCode.html here.
but when i do a recvfrom() it waits until there is anything to receive right?
obviously this isnt good enough for a game (gotta carry on even if there isnt any info coming in)
so i want to either check there is some information, or get an instant return if there isnt.
i think this is where select() comes in, but im not sure
can someone help?
__________________
graham "red" reeves.
red@deadpenguin.org
www.deadpenguin.org
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
ok go to my site to tutorials-->windows
and then read about the udp tutorial
it will answer your question...
and show you a better way to use sockets
good luck!
QSoft
Edited by - Arkon on May 23, 2001 8:26:16 AM
and then read about the udp tutorial
it will answer your question...
and show you a better way to use sockets
good luck!
QSoft
Edited by - Arkon on May 23, 2001 8:26:16 AM
thanks a lot, werking perfectly
one more thing i cant work out, from a SOCKADDR_IN how do i get the ip address?
say into byte ips[4];
thanks :]
__________________
graham "red" reeves.
red@deadpenguin.org
www.deadpenguin.org
one more thing i cant work out, from a SOCKADDR_IN how do i get the ip address?
say into byte ips[4];
thanks :]
__________________
graham "red" reeves.
red@deadpenguin.org
www.deadpenguin.org
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
no matter, it worked this time, just not last time :]
__________________
graham "red" reeves.
red@deadpenguin.org
www.deadpenguin.org
|
__________________
graham "red" reeves.
red@deadpenguin.org
www.deadpenguin.org
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
if you wanna see it in action, get the latest ver of my game from uberspace.net
run the game, and drop down the console (`) and type "send localhost foo"
:]
__________________
graham "red" reeves.
red@deadpenguin.org
www.deadpenguin.org
run the game, and drop down the console (`) and type "send localhost foo"
:]
__________________
graham "red" reeves.
red@deadpenguin.org
www.deadpenguin.org
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
You don''t have permission to access /files/uberspace011.zip on this server.
check it out
Arkon
[QSoft Systems]
check it out
Arkon
[QSoft Systems]
thanks for telling me, ive told lots of ppl to get it :]
fixed now
__________________
graham "red" reeves.
red@deadpenguin.org
www.deadpenguin.org
fixed now
__________________
graham "red" reeves.
red@deadpenguin.org
www.deadpenguin.org
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
Instead of:
byte ips[4]={0};
memcpy(ips,&incoming_sockaddr.sin_addr.S_un,4);
char fromwho[256]={0};
sprintf(fromwho,"%d.%d.%d.%d",ips[0],ips[1],ips[2],ips[3]);
The method you used above doesn''t convert the sin_addr from network byte order to host byte order. Now depending on your machine, these may be the same![](smile.gif)
Instead you may want to try:
char* incoming_ip = inet_ntoa(incoming_sockaddr.sin_addr.S_un);
Just make sure you copy the result to a variable (using strcpy) as the pointer returned by inet_ntoa is an internal Winsock buffer that will get overwritten on the next call to inet_ntoa.
Dire Wolf
www.digitalfiends.com
byte ips[4]={0};
memcpy(ips,&incoming_sockaddr.sin_addr.S_un,4);
char fromwho[256]={0};
sprintf(fromwho,"%d.%d.%d.%d",ips[0],ips[1],ips[2],ips[3]);
The method you used above doesn''t convert the sin_addr from network byte order to host byte order. Now depending on your machine, these may be the same
![](smile.gif)
Instead you may want to try:
char* incoming_ip = inet_ntoa(incoming_sockaddr.sin_addr.S_un);
Just make sure you copy the result to a variable (using strcpy) as the pointer returned by inet_ntoa is an internal Winsock buffer that will get overwritten on the next call to inet_ntoa.
Dire Wolf
www.digitalfiends.com
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
www.digitalfiends.com
thanks, im sure thatll stop me getting a headache later on :]
whilst everyones in a good helpful mood anyone wanna tell me how to do a reverse dns from an ip or in_addr?
i found it once, but lost it again (and havent spotted it in the winsock.h)
__________________
graham "red" reeves.
red@deadpenguin.org
www.deadpenguin.org
whilst everyones in a good helpful mood anyone wanna tell me how to do a reverse dns from an ip or in_addr?
i found it once, but lost it again (and havent spotted it in the winsock.h)
__________________
graham "red" reeves.
red@deadpenguin.org
www.deadpenguin.org
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement