UDP network stuff

BlitzPlus Forums/BlitzPlus Programming/UDP network stuff

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hmmm, well it's easy enough to mod it to look on all adapters. If I run this version on our gateway machine, it finds the LAN connection (hostIP 1), and reports that it cannot find the broadcast IP for the ADSL modem (hostIP 2), and sets it to zero. On another macine (double LANned), it reports both adapter broadcast IPs. Now we have:

hadapters - number of adapters
bcastip(n) - broadcasting IP for adapter (n), set to zero if undetermined.

As for deciding which one to broadcast on, good question. I suppose it could be left to the user to decide, which sort of gives me the mechanism for selecting which adapter(s) will be used to host (though technically, it would be hosting on all of them, the server presence broadcast would only appear on one adapter). Perhaps send out the broadcast data on all the adapters that allow it, and assume that any bcastip(n) set to zero (such as the ADSL modem) ain't for the broadcastin'.


;===========================================
;BROADCAST IP DETERMINIFICATIONALIZOMATIC v2
;===========================================


hadapters=CountHostIPs("")
Dim bcastip(hadapters)
stream=CreateUDPStream(8123)
UDPTimeouts 5



For x=1 To hadapters
	
	bcastip(x)=HostIP(x)

	Repeat

		bcastip(x)=bcastip(x)+1
		WriteString stream,"HELLO SAILOR"
		SendUDPMsg stream,bcastip(x),8123
		recv=RecvUDPMsg(stream)
		nmsg$=ReadString$(stream)

	Until nmsg$="HELLO SAILOR" Or (255 And bcastip(x))=0

	If nmsg$="HELLO SAILOR" Then Notify "NIC ("+x+") Broadcast IP: "+DottedIP$(bcastip(x))
	If recv=0 Then bcastip(x)=0:Notify "Failed to determine NIC("+x+") broadcast IP."

Next

CloseUDPStream stream


Aha! Found the code highlighting thingy.

You're right of course about broadcasting possibly clashing horns with firewalls, but I guess that's firewalls for you. I suppose it should be fairly safe. I guess it would be more tidy to do it via an API call, although if this routine caused upset to firewalls, then the game would likely do the same. I suppose if there was an easy workaround for the firewall issues, it wouldn't really be much of a firewall, would it...

Man, I sure do alot of guessing and supposing.


[edit:] Oh, and in the event of checking for an ip like 192.168.x.x, you could change (255 AND BCASTIP(n)) to (65535 AND BCASTIP(n)). And change the UDPtimeout value. Or go away and medium-boil an egg (worst case) while you wait. It appears to work with UDP timeouts set to zero, and takes about 6 or so seconds to evaluate all 65535 possibilities. Man is it crude though!