Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ UDP Send and Listen Information on Ports

UDP Send and Listen Information on Ports

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Onoitsu2   USA  (248 posts)  Bio
Date Sat 02 Dec 2006 06:15 AM (UTC)
Message
I was just messing around with the Immediate window, and UDP Sending, to a "program" I scripted in AutoIt, and noticed an issue in the port numbering. In LUA you can use ANY actual port number, as it will accept a LONG integer, and yet in VP it will only accept a SHORT integer, so only to about 32k and some hundreds more ...

It is not a real problem, except for those that try to send on a port that is VERY unlikely to be used for any COMMERCIAL application.

I don't know if it happens in other languages, but it is quite possible it would.

Just thought I'd post my findings.

Laterzzz
Onoitsu2
Top

Posted by Nick Gammon   Australia  (23,132 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 02 Dec 2006 08:05 AM (UTC)
Message
What is VP?

Anyway, in the TCP/IP protocol, ports are a 16-bit number (a short) so one larger than 65535 is not possible.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #2 on Mon 04 Dec 2006 06:18 AM (UTC)
Message
sorry lol VP = VB, as in VBS, you can only use a port numbering up to 32767, and yet in LUA you can use up to the 65535 limit.

I was rushed to finish posting the messages last night ...

Laterzzz,
Onoitsu2
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #3 on Mon 04 Dec 2006 06:27 AM (UTC)
Message
What do you mean by 'Lua'? Lua has no native support for sockets. Is this using the Lua Socket library? It states in the reference (for TCP/IP, at least) that the number can't be greater than 65k.
http://www.cs.princeton.edu/~diego/professional/luasocket/tcp.html#bind

However Lua itself doesn't distinguish between the various integer types (the default native number type is double), so it would let you enter whatever you want.

And is VB using a signed or unsigned short? A signed would go to 32k, but the unsigned short would go up to 65k which is the proper value.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Nick Gammon   Australia  (23,132 posts)  Bio   Forum Administrator
Date Reply #4 on Mon 04 Dec 2006 07:25 AM (UTC)
Message
He was talking about UdpSend function:

http://www.gammon.com.au/scripts/doc.php?function=UdpSend

Since the prototype specifies a short, and not an unsigned short, you can probably only go to 32767.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #5 on Mon 04 Dec 2006 07:34 AM (UTC)
Message
Ah, ok; so the VB binding to Winsock is what's limiting things? I checked the UDP protocol (e.g. http://en.wikipedia.org/wiki/User_Datagram_Protocol) and it says that the max is 65k, like TCP/IP.

I don't remember how VB handles type coercion between signed/unsigned types. If you were to enter 65k into a 'short' parameter, would that wrap around to the appropriate negative number (and then back to positive by the UDP handler) or does that generate an error?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Nick Gammon   Australia  (23,132 posts)  Bio   Forum Administrator
Date Reply #6 on Mon 04 Dec 2006 09:35 AM (UTC)
Message
It is probably my fault for specifying short, MFC has generated this function prototype:


long CMUSHclientDoc::UdpSend(LPCTSTR IP, short Port, LPCTSTR Text) 


However a bit of testing reveals that it appears to correctly handle a number larger than 32767, as internally it calls htons, which has this prototype:


u_short htons (
  u_short hostshort  
);


It passes down "Port" to that function, so even though technically it is negative it all seems to resolve itself.

Thus you should be able to use a port in the range 0 to 65535.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


19,473 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.