Jump to content

Serverless UDP connections


Recommended Posts

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? :)

Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...