Try my new website:
www.urcho.com
- the new SIMPLE social network
Sign up
|
287
members |
114
snippets
Search for:
ALL
POPULAR
File Controls
Multiplayer Code
2D Effects
3D Effects
Oldskool demos
Basic Functions
Maths/Physics
Sound
Tutorials
Misc
Username:
Password:
Sign up
UDP Protocol Example by cermit
[
back
]
Author:
Archive
| Viewed:
1006
times | Language:
BlitzBasic 3D
| Category:
Multiplayer Code
; UDP Protocol Example ; ; Set font font% = LoadFont( "Lucida Console", 10, True, False, False ) SetFont font% ; Initialize Network host_count% = CountHostIPs( "" ) If host_count = 0 Then Print_Error( "Failed to initiate network" ) WaitKey End Else integer_ip% = HostIP( 1 ) dotted_ip$ = DottedIP( integer_ip ) Print_Status( "Network initialized successfuly", " IP " + dotted_ip ) EndIf ; Create UDP Streams udp_a% = CreateUDPStream( 1000 ) udp_b% = CreateUDPStream( 2000 ) If udp_a + udp_b = False Then Print_Error( "Failed to create one stream or another" ) WaitKey End EndIf ; Send Message msg$ = "Hello sheep!" WriteString( udp_a, msg ) SendUDPMsg udp_a, integer_ip, 2000 Print_Status( "Udp_a sent message", " " + msg ) ; Receive Message Repeat If RecvUDPMsg( udp_b ) msg = ReadString( udp_b ) Print_Status( "Udp_b received message", " " + msg ) Exit EndIf Forever ; Neatly close UDP Streams CloseUDPStream udp_a CloseUDPStream udp_b Print_Status( "UDP streams were closed", "" ) ; End program Print_Status( "Have a nice day!", " Any key .." ) FreeFont font% WaitKey End ; Print Status function Function Print_Status( main_str$, sub_str$ ) Color 0, 255, 0 Print main_str Color 255, 255, 0 Print sub_str Print "" End Function ; Print Error Function Function Print_Error( main_str$ ) Color 255, 0, 0 Print main_str$ Print " Any key .." End Function
Author Comments:
UDP Protocol Example
Login or
create an account
to comment on this snippet