UDP network stuff

BlitzPlus Forums/BlitzPlus Programming/UDP network stuff

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

Here's a modification of the code above that counts back fro the .255 address to the current IP, significantly reducing the work in most cases, as well as speeding things up:

;==================================================== 
;BROADCAST IP DETERMINIFICATIONALIZOMATICIFIERTRON v3
;==================================================== 
hadapters=CountHostIPs("") 
Dim bcastip(hadapters) 
stream=CreateUDPStream(8123) 
UDPTimeouts 5
For x=1 To hadapters 
	bcastip(x)=HostIP(x)-(HostIP(x) Mod 256) + 255
	Notify DottedIP$(bcastip(x))
	Repeat 
		WriteString stream,"HELLO SAILOR" 
		SendUDPMsg stream,bcastip(x),8123 
		recv=RecvUDPMsg(stream) 
		nmsg$=ReadString$(stream) 
		bcastip(x)=bcastip(x)-1
	Until nmsg$="HELLO SAILOR" Or bcastip(x)=HostIP(x)
	If nmsg$="HELLO SAILOR" Then Notify "NIC ("+x+") Broadcast IP: "+DottedIP$(bcastip(x)+1) 
	If recv=0 Then bcastip(x)=0:Notify "Failed to determine NIC("+x+") broadcast IP." 
Next 

CloseUDPStream stream 


As a side-note: you can see another significant speed increase by reducing the UDP timeout period, although I am not sure how that would be affected on slow networks adapters... during my tests UDPTimeout of 0 or 1 worked without problems as well, finishing the code above almost instantaneous for all adapters.