January 16, 2021, 09:54:29 PM

Author Topic: BaH.Inet not working (Windows)  (Read 193 times)

Offline wookie22

  • Jr. Member
  • **
  • Posts: 55
    • Hidden Deep
BaH.Inet not working (Windows)
« on: November 23, 2020, 11:05:15 AM »
Hello,

I need to get local lan IP of PC. I've read BaH.Inet is for that but I can't run any example because of errors.

I'm using Vanilla. Can anyone help? Maybe you know other way to get that IP?

Thanks
Hidden Deep - 2D Action & Exploration Sci-Fi Thriller for PC/Mac/Linux
http://www.hiddendeepgame.com

Offline Derron

  • Hero Member
  • *****
  • Posts: 3331
Re: BaH.Inet not working (Windows)
« Reply #1 on: November 23, 2020, 11:25:36 AM »
did not test it with vanilla ... but should work there too:

Code: BlitzMax
  1. SuperStrict
  2. Framework Brl.StandardIO
  3. Import Brl.Socket
  4.  
  5.  
  6. 'will print "0.0.0.0"
  7. Local socketUDP:TSocket = CreateUDPSocket()
  8. Local socketTCP:TSocket = CreateTCPSocket()
  9. ?Not bmxng
  10. Print "UDP: " + DottedIP( SocketLocalIP( socketUDP ) )
  11. Print "TCP: " + DottedIP( SocketLocalIP( socketTCP ) )
  12. ?bmxng
  13. Print "UDP: " + SocketLocalIP( socketUDP )
  14. Print "TCP: " + SocketLocalIP( socketTCP )
  15. ?
  16. 'iterate over ALL IPs defined for localhost
  17. ?Not bmxng
  18. For Local ip:Int = EachIn HostIps( "localhost" )
  19.           Print DottedIP(ip)
  20. Next
  21. ?bmxng
  22. For Local ip:String = EachIn HostIps( "localhost" )
  23.           Print ip
  24. Next
  25. ?
  26.  

In Vanilla the commands return "integer", in NG they return "strings" (as you cannot pack an "IPv6" into a single integer...). NG also already "dots" them (1.2.3.4).


Why are the first two commands returning "0" (0.0.0.0) ?? They are not "bound" to a remote IP and so it is not known which IP you used.
Which?
Check out the for loop. And think about what happens if you place two NICs ("network cards") into your computer, or add some virtual NIC (think about WireShark etc - to sniff into your multiplayer code).

But most of the time your computer defined a "localhost" which corresponds to "my computer". If your computer has a networkname ("wookie22pc") you could use that too - the same way you could lookup other computers in your local network.

In IPv4 you can also broadcast around (local IP - with ".255" at the end). Useful if you want to announce a LAN server. I did/do it this way to broadcast that I host a game - and automatically (without entering the "server IP") the game is listed on game clients waiting in the "LAN lobby".

With IPv6 there is no broadcast available - at least not "this way". Dunno when IPv6 becomes so much standard that IPv4 is no longer used ... so maybe prepare yourself of using it sooner or later. Yet I have to confess: this wont work with vanilla - you would have to modify the modules on your own, no backport "yet".


bye
Ron

Offline wookie22

  • Jr. Member
  • **
  • Posts: 55
    • Hidden Deep
Re: BaH.Inet not working (Windows)
« Reply #2 on: November 23, 2020, 11:49:28 AM »
Thank you.
I got only 127.0.0.1 while my local IP is 10.93.8.21

But I'll try that broadcasting trick - if it work when I get my laptop
Hidden Deep - 2D Action & Exploration Sci-Fi Thriller for PC/Mac/Linux
http://www.hiddendeepgame.com

Offline Derron

  • Hero Member
  • *****
  • Posts: 3331
Re: BaH.Inet not working (Windows)
« Reply #3 on: November 23, 2020, 12:03:08 PM »
Then try with your "real" hostname.


I identify my "local ip" once I received client replies ... as I then have a connection (bound socket) and can read at which IP of mine they had connected (ip:port).
For UDP also of importance: you wont define which port to use - you send, they reply - and then you see what outgoing port was used.
So for initial connection I used TCP (where you open your port, do the NAT in your firewall ... aka port redirection). This is required as the server needs some kind of "fixed" port on where clients could try to connect.


bye
Ron

Offline Derron

  • Hero Member
  • *****
  • Posts: 3331
Re: BaH.Inet not working (Windows)
« Reply #4 on: November 23, 2020, 12:06:17 PM »
You might also check out this code here:
https://www.syntaxbomb.com/index.php?topic=1831.0


bye
Ron

Offline wookie22

  • Jr. Member
  • **
  • Posts: 55
    • Hidden Deep
Re: BaH.Inet not working (Windows)
« Reply #5 on: November 23, 2020, 01:55:40 PM »
Thanks again Derron. That ipconfig read worked. I will soon start to experiment with making lobby
Hidden Deep - 2D Action & Exploration Sci-Fi Thriller for PC/Mac/Linux
http://www.hiddendeepgame.com

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal