; UDPStreamIP Example ; ------------------- ; This program is both ends of a UDP conversation at once: two ; streams on this machine swap packets over the loopback address. ; The loopback address 127.0.0.1 as a packed integer loopback=(127 Shl 24) Or 1 host=CreateUDPStream(5407) If host=0 Then Print "Could not bind port 5407 (it may be in use)" Else ; UDPStreamIP returns the address the stream is bound to. ; CreateUDPStream listens on ALL of the machine's interfaces, ; so this reports 0 - which DottedIP renders as 0.0.0.0 Print "Host: UDPStreamIP = "+UDPStreamIP(host)+" ("+DottedIP$(UDPStreamIP(host))+")" Print "Host: UDPStreamPort = "+UDPStreamPort(host) Print "(0.0.0.0 means 'every local interface', not an error)" player=CreateUDPStream() If player=0 Then Print "Player: could not create a UDP stream" Else WriteLine player,"Where are you?" SendUDPMsg player,loopback,5407 UDPTimeouts 500 If RecvUDPMsg(host)=0 Then Print "Host: no packet arrived" Else Print "Host: message = '"+ReadLine$(host)+"'" ; Contrast: UDPMsgIP gives the REMOTE address a packet ; came from - here the loopback address itself Print "Host: the packet came from "+DottedIP$(UDPMsgIP(host)) EndIf CloseUDPStream player EndIf CloseUDPStream host EndIf Print "" Print "Press any key to close the example" WaitKey End