Sign in to follow this  
Followers 0
CodyBarrett

Serverless UDP connections

2 posts in this topic

well for the last 3 months on and off i have been looking for a UDP example script that would be usefull to learn from.. i know how to make a TCP multiclient... though that needs a server.. what i would like is (for my current Chess PVP game project) is:

*any UDP examples on how to do it without a server (person starts up game... waits and another person connects and they play..)

*possibly some directions in where to learn from

*is it even possible for a UDP serverliess PvP game..

i HAVE seen a few UDP examples around here... but i have no idea how they function.. so please any help? :)

Share this post


Link to post
Share on other sites



#include<GuiConstantsEx.au3>
#include<GUIEdit.au3>
#include<EditConstants.au3>
#include<ButtonConstants.au3>
Opt("GUIOnEventMode" , 1)
UDPStartup()
$s=UDPBind(@IPAddress1,8080)
$d=UDPOpen("255.255.255.255" , 8080,1)
$GUI=GUICreate("Test",410,235)
$edit=GUICtrlCreateEdit("",5,5,400,200)
GUICtrlSetStyle($edit,$ES_READONLY)
$input=GUICtrlCreateInput("" , 5 ,210,350,20)
$b=GUICtrlCreateButton("Send" , 355,210,50,20,$BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent(-1 , "_send")
GUISetOnEvent($GUI_EVENT_CLOSE,"quit")
GUISetState()
GUICtrlSetState($input,$GUI_FOCUS)
While 1
    Sleep(100)
    $recv=UDPRecv($s,4096,2)
    If IsArray($recv) Then _GUICtrlEdit_AppendText($edit,StringFormat("[%s:%s] > %s\n" , $recv[1],$recv[2],$recv[0]))
WEnd
Func quit()
    UDPShutdown()
    Exit
EndFunc
Func _send()
    $data=GUICtrlRead($input)
    GUICtrlSetData($input,"")
    GUICtrlSetState($input,$GUI_FOCUS)
    UDPSend($d,$data)
EndFunc

here's a simple example :) you can even test in on your local machine. BUT! because it uses broadcasting you cannot listen on the same port twice so if you run more than one instances of the script only the first one will recv the data but all of them can send :)

P.S.: you need the latest beta


Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0