IP address is too big?!

Blitz3D Forums/Blitz3D Programming/IP address is too big?!

JoshK(Posted 2004) [#1]
Say you have an IP addres like this:
64.138.174.21

Convert it to an integer:
6413817421

And it is a bigger number than a 32-bit integer can handle!

How do you pass ip address to the UDP commands?!


JoshK(Posted 2004) [#2]
I am guessing you trim off the last 2 numbers. Can anyone confirm this?


D4NM4N(Posted 2004) [#3]
Ive never used udp commands so I probably dont know what im talking about.... But doesnt blitz handle them as strings? Most in most languages its 4 seperate bytes. If you did convert it to an integer how would you know where the breaks are ie 192132118 could be 192.13.21.18 or 192.132.1.18 or variants thereof??

Dunno!


SoggyP(Posted 2004) [#4]
Hi Folks,

Loathe as I am to offer this thankless goit advice why not split it into it's four constituent parts, eg, a = 192, b = 13, c= 21 and d 18 then

ip = (a shl 24 ) or (b shl 16) or (c shl 8) or d

there you have a 32 bit number that can be decoded the other side by shifting the other way.

Later,

Jes


JoshK(Posted 2004) [#5]
How does that help when you are giving the SendUDPMsg() command an ip value?

Oooooh, I see. It's the old IP--> Int routine. Haven't dealth with this stuff in a long time.


Warren(Posted 2004) [#6]
You're welcome.


Andy UK(Posted 2004) [#7]
if you are send the packet to a blitz client you could ask the client to first open a tcp port to your app... no need to send data this is enough for you to get the integer ip then use it with the udp commands... thats if your using a blitz client also.

client does this:
ipserver=OpenTCPStream("your address",8080)
closetcpstream ipserver

your app does this:
ipserver=CreateTCPServer(8080)
Repeat
ipstream=AcceptTCPStream(ipserver)
Delay 1
Until ipstream
ip=TCPStreamIP(ipstream)
clientip$=DottedIP$(ip)
...........
...........
SendUDPMsg stream,ip,8081


John Pickford(Posted 2004) [#8]
That's an odd way to convert a 4 byte number to an integer. In fact, how can you possibly convert back to the original 4 bytes?

Do it in hex and then it will fit.


SoggyP(Posted 2004) [#9]
Hi folks,

@JP: Who?

Later,

Jes


John Pickford(Posted 2004) [#10]
Sorry soggy I was referring to Halo's initial post. You posted the correct method.