SDL_Net question

Hello,
i have a stupid problem with SDL_net.

i have a client/server application using UDP packets.

in my code i have something like this :

packet->address=myaddress;
packet->address.port=myport;
SDLNet_UDP_Send(mysocket,-1,packet)//-1 so use internal address

the problem is in :
packet->address.port=myport;

myport is an int readed from console, but packet->address.port is a Uint16.

i have tryed both using a cast :
packet->address.port=(Uint16)myport;
and using function:
packet->address.port=SDL_SwapBE16(myport);

int both cases there is an error, but if i set it manually it work ,
example:
(27015 as int will be : 32105)
packet->address.port=32105; //OK

a similar error like this is located here :
http://twomix.devolution.com/pipermail/sdl/2004-February/059772.html

Can you give me some suggestions ?

Thanks in advance.
Alberto Glarey

Hmm well an Uint16 ranges, obviously, from 0 to 65535, where an Int32
(or int) ranges, obviously, from -2147483648 to 2147483647. As you can
see, as long as you specify a value between 0 and 65535 on your console,
the Int32 value should ALWAYS be converted properly to an Uint16 value.
Have you tried debugging to see what’s going on?

Marc

Alberto Glarey wrote:>

Hello,
i have a stupid problem with SDL_net.

i have a client/server application using UDP packets.

in my code i have something like this :

packet->address=myaddress;
packet->address.port=myport;
SDLNet_UDP_Send(mysocket,-1,packet)//-1 so use internal address

the problem is in :
packet->address.port=myport;

myport is an int readed from console, but packet->address.port is a Uint16.

i have tryed both using a cast :
packet->address.port=(Uint16)myport;
and using function:
packet->address.port=SDL_SwapBE16(myport);

int both cases there is an error, but if i set it manually it work ,
example:
(27015 as int will be : 32105)
packet->address.port=32105; //OK

a similar error like this is located here :
http://twomix.devolution.com/pipermail/sdl/2004-February/059772.html

Can you give me some suggestions ?

Thanks in advance.
Alberto Glarey


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Bye,
Marc ‘Foddex’ Oude Kotte

-=-=-=-=-=-=-=-=-=-=-=-=-
Need a programmer?
Go to http://www.foddex.net

Hmmm I read your post more thoroughly this time, try this:

packet->address.port=SDL_SwapBE16((Uint16)myport);

HTH

Marc

M.A. Oude Kotte wrote:> Hmm well an Uint16 ranges, obviously, from 0 to 65535, where an Int32

(or int) ranges, obviously, from -2147483648 to 2147483647. As you can
see, as long as you specify a value between 0 and 65535 on your console,
the Int32 value should ALWAYS be converted properly to an Uint16 value.
Have you tried debugging to see what’s going on?

Marc

Alberto Glarey wrote:

Hello,
i have a stupid problem with SDL_net.

i have a client/server application using UDP packets.

in my code i have something like this :

packet->address=myaddress;
packet->address.port=myport;
SDLNet_UDP_Send(mysocket,-1,packet)//-1 so use internal address

the problem is in :
packet->address.port=myport;

myport is an int readed from console, but packet->address.port is a
Uint16.

i have tryed both using a cast :
packet->address.port=(Uint16)myport;
and using function:
packet->address.port=SDL_SwapBE16(myport);

int both cases there is an error, but if i set it manually it work ,
example:
(27015 as int will be : 32105)
packet->address.port=32105; //OK

a similar error like this is located here :
http://twomix.devolution.com/pipermail/sdl/2004-February/059772.html

Can you give me some suggestions ?

Thanks in advance.
Alberto Glarey


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Bye,
Marc ‘Foddex’ Oude Kotte

-=-=-=-=-=-=-=-=-=-=-=-=-
Need a programmer?
Go to http://www.foddex.net

Don’t forget that you have to give “SDLNet_UDP_Open(Uint16)” a host-based byte order port.
But you have to write a net-based byte order in the “packet->address.port”.
Do you have this ? :
udp_socket = SDLNet_UDP_Open(UDP_PORT);
packet->address.port = SDL_SwapBE16(Uint16)UDP_PORT);

Nuage wrote:

Don’t forget that you have to give “SDLNet_UDP_Open(Uint16)” a
host-based byte order port.
But you have to write a net-based byte order in the “packet->address.port”.
Do you have this ? :
udp_socket = SDLNet_UDP_Open(UDP_PORT);
packet->address.port = SDL_SwapBE16(Uint16)UDP_PORT);

this was the error !!!

I was also opening the server port using SDL_SwapBE16().

Thank you for pointing me in the right direction.