Advertisement

winsock: recieving

Started by May 23, 2001 06:54 AM
9 comments, last by redmonkey 23 years, 8 months ago
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
Advertisement
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
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
no matter, it worked this time, just not last time :]

  	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]);  


__________________
graham "red" reeves.

red@deadpenguin.org
www.deadpenguin.org
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
go back to my site(if you want )
and take a look in the code snippets...

Arkon
[QSoft Systems]
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
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
Advertisement
You don''t have permission to access /files/uberspace011.zip on this server.

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
__________________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

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
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
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org

This topic is closed to new replies.

Advertisement