Jump to content

Search the Community

Showing results for tags 'no server'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. This script is going to be part of a bigger project that I'm working on (HINT: It involves UDP). The following code may/may not have bugs in it, I'm posting it because I need suggestions on how to improve it. #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GuiIPAddress.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <Array.au3> Local $ClientList[1][2] = [[-1, -1]] UDPStartup() $UserName = @ComputerName $Form1 = GUICreate($UserName & " - ChAT TeST", 445, 200) ; GUI for sending and recieving messages $Edit1 = GUICtrlCreateEdit("", 5, 5, 282, 161) GUICtrlSetFont(-1, 7.5, Default, Default, "Lucida Console") GUICtrlSetData(-1, "Chat Log:", "append") GUICtrlSetState(-1, $GUI_DISABLE) $Input1 = GUICtrlCreateInput("", 5, 169, 281, 21) GUICtrlSendMsg(-1, 0x1500 + 1, False, 'Type here and press ENTER to send') GUICtrlSetState(-1, $GUI_DISABLE) $IPAddress3 = _GUICtrlIpAddress_Create($Form1, 290, 5, 130, 21) _GUICtrlIpAddress_Set($IPAddress3, "0.0.0.0") $Button1 = GUICtrlCreateButton("Add", 420, 5, 25, 21) $hListview = GUICtrlCreateListView("#|IP", 290, 27, 155, 150) _GUICtrlListView_SetColumnWidth($hListview, 0, 25) _GUICtrlListView_SetColumnWidth($hListview, 1, 125) $YOUR_IP_HERE = GUICtrlCreateInput(@IPAddress1, 300, 180, 130, 20, BitOR($SS_CENTERIMAGE, $SS_CENTER)) GUICtrlSetTip(-1, "Your IP") ; Bind to socket 80 - Used for recieving messages Local $INsocket = UDPBind(@IPAddress1, 80) If @error Then Exit 1111 ; Bind to socket 81 - Used for recieving system messages Local $SYSTEMsocket = UDPBind(@IPAddress1, 81) If @error Then Exit 1112 ; $fAllowSend flag prevents sending of a typed message when the edit is updated Local $IP, $OUTsocket, $fAllowSend = True ; Register an Exit function that cleans up by closing all sockets used for sending to clients OnAutoItExitRegister("Cleanup") ; Shows the GUI GUISetState(@SW_SHOW) ; Timer is used to check every 25 ms for messages $RecvTimer = TimerInit() While 1 $nMsg = GUIGetMsg() If $nMsg = $GUI_EVENT_CLOSE Then Exit If $nMsg = $YOUR_IP_HERE Then GUICtrlSetData($YOUR_IP_HERE, @IPAddress1) If $nMsg = $Input1 Then $Text = GUICtrlRead($Input1) If StringStripWS($Text, 8) <> "" And $fAllowSend = True Then ; Sends the message to all of the clients For $x = 0 To UBound($ClientList) - 1 UDPSend($ClientList[$x][0], @IPAddress1 & "::" & $UserName & ": " & $Text) Next GUICtrlSetData($Edit1, @CRLF & $UserName & ": " & $Text, "append") GUICtrlSetData($Input1, "") EndIf EndIf If $nMsg = $Button1 Then If $IP <> _GUICtrlIpAddress_Get($IPAddress3) And _GUICtrlIpAddress_Get($IPAddress3) <> @IPAddress1 And _GUICtrlIpAddress_Get($IPAddress3) <> "0.0.0.0" And Not _IsIPInList(_GUICtrlIpAddress_Get($IPAddress3)) Then $IP = _GUICtrlIpAddress_Get($IPAddress3) ; Sends a CR (Connection Request) $OUTsocket = UDPOpen($IP, 81) UDPSend($OUTsocket, "CR:" & @IPAddress1) $iSearch = -1 For $x = 0 To UBound($ClientList) - 1 If $ClientList[$x][0] <> -1 Then ContinueLoop If $ClientList[$x][0] = -1 Then $iSearch = $x ExitLoop EndIf Next If $iSearch = -1 Then $Bounds = UBound($ClientList) ReDim $ClientList[$Bounds + 1][2] $iSearch = $Bounds EndIf $ClientList[$iSearch][0] = UDPOpen($IP, 80) $ClientList[$iSearch][1] = $IP ConsoleWrite("Connected to: " & $IP & " @error = " & @error & @CRLF) $List = "CL" For $x = 0 To UBound($ClientList) - 1 If $x = $iSearch Or $ClientList[$x][1] = @IPAddress1 Then ContinueLoop $List &= ":" & $ClientList[$x][1] Next If $List <> "CL" Then UDPSend($OUTsocket, $List) EndIf UDPCloseSocket($OUTsocket) ; Sends a Connection request to all of the clients with no re-send (CRR) For $x = 0 To UBound($ClientList) - 1 If $x = $iSearch Then ContinueLoop $OUTsocket = UDPOpen($ClientList[$x][1], 81) UDPSend($OUTsocket, "CRR:" & $IP) UDPCloseSocket($OUTsocket) Next GUICtrlSetState($Edit1, $GUI_ENABLE) GUICtrlSetState($Input1, $GUI_ENABLE) _GUICtrlIpAddress_Set($IPAddress3, "0.0.0.0") _UpdateListView() If GUICtrlRead($Edit1) <> "Chat Log:" And MsgBox(4, "ChAt TeST", "Send Chat History to " & $IP & "?") = 6 Then $OUTsocket = UDPOpen($ClientList[$iSearch][1], 81) UDPSend($OUTsocket, "CH:" & @IPAddress1 & ":" & StringReplace(StringReplace(GUICtrlRead($Edit1), "/n", "//n"), @CRLF, "/n")) UDPCloseSocket($OUTsocket) EndIf EndIf EndIf If TimerDiff($RecvTimer) >= 25 Then $data = UDPRecv($INsocket, 1000000) If $data <> "" Then If IsBinary($data) Then $data = BinaryToString($data) If StringInStr($data, "::") Then ; Only recieve messages from clients in the list $Exp = StringRegExp($data, "([0-9.]{7,15})::(.*)", 1) If @error == 0 And UBound($Exp) == 2 And _IsIPInList($Exp[0]) Then $fAllowSend = False GUICtrlSetData($Edit1, @CRLF & $Exp[1], "append") $fAllowSend = True EndIf EndIf EndIf $data = UDPRecv($SYSTEMsocket, 100000) If $data <> "" Then ConsoleWrite("Recieved: " & $data & @CRLF) $Exp = StringRegExp($data, "CR:([0-9.]{7,15})", 1) If @error = 0 Then $IP = $Exp[0] $iSearch = -1 For $x = 0 To UBound($ClientList) - 1 If $ClientList[$x][0] <> -1 Then ContinueLoop If $ClientList[$x][0] = -1 Then $iSearch = $x ExitLoop EndIf Next If $iSearch = -1 Then $Bounds = UBound($ClientList) ReDim $ClientList[$Bounds + 1][2] $iSearch = $Bounds EndIf $ClientList[$iSearch][0] = UDPOpen($IP, 80) $ClientList[$iSearch][1] = $IP ConsoleWrite("Connected to (CR): " & $IP & " @error = " & @error & @CRLF) $List = "CL" For $x = 0 To UBound($ClientList) - 1 If $x = $iSearch Or $ClientList[$x][1] = @IPAddress1 Then ContinueLoop $List &= ":" & $ClientList[$x][1] Next If $List <> "CL" Then $OUTsocket = UDPOpen($ClientList[$iSearch][1], 81) UDPSend($OUTsocket, $List) UDPCloseSocket($OUTsocket) EndIf For $x = 0 To UBound($ClientList) - 1 If $x = $iSearch Then ContinueLoop $OUTsocket = UDPOpen($ClientList[$x][1], 81) UDPSend($OUTsocket, "CRR:" & $IP) UDPCloseSocket($OUTsocket) Next GUICtrlSetState($Edit1, $GUI_ENABLE) GUICtrlSetState($Input1, $GUI_ENABLE) _UpdateListView() If GUICtrlRead($Edit1) <> "Chat Log:" And MsgBox(4, "ChAt TeST", "Send Chat History to " & $IP & "?") = 6 Then $OUTsocket = UDPOpen($ClientList[$iSearch][1], 81) UDPSend($OUTsocket, "CH:" & @IPAddress1 & ":" & StringReplace(StringReplace(GUICtrlRead($Edit1), "/n", "//n"), @CRLF, "/n")) UDPCloseSocket($OUTsocket) EndIf EndIf $Exp = StringRegExp($data, "CL:(.*)", 1) If @error = 0 Then $List = StringSplit($Exp[0], ":") For $y = 1 To $List[0] $IP = $List[$y] $iSearch = -1 For $x = 0 To UBound($ClientList) - 1 If $ClientList[$x][0] <> -1 Then ContinueLoop If $ClientList[$x][0] = -1 Then $iSearch = $x ExitLoop EndIf Next If $iSearch = -1 Then $Bounds = UBound($ClientList) ReDim $ClientList[$Bounds + 1][2] $iSearch = $Bounds EndIf $ClientList[$iSearch][0] = UDPOpen($IP, 80) $ClientList[$iSearch][1] = $IP ConsoleWrite("Connected to(CL): " & $IP & " @error = " & @error & @CRLF) _UpdateListView() Next EndIf $Exp = StringRegExp($data, "CRR:([0-9.]{7,15})", 1) If @error = 0 Then $IP = $Exp[0] $iSearch = -1 For $x = 0 To UBound($ClientList) - 1 If $ClientList[$x][0] <> -1 Then ContinueLoop If $ClientList[$x][0] = -1 Then $iSearch = $x ExitLoop EndIf Next If $iSearch = -1 Then $Bounds = UBound($ClientList) ReDim $ClientList[$Bounds + 1][2] $iSearch = $Bounds EndIf $ClientList[$iSearch][0] = UDPOpen($IP, 80) $ClientList[$iSearch][1] = $IP ConsoleWrite("Connected to(CRR): " & $IP & " @error = " & @error & @CRLF) GUICtrlSetState($Edit1, $GUI_ENABLE) GUICtrlSetState($Input1, $GUI_ENABLE) _UpdateListView() EndIf $Exp = StringRegExp($data, "DEL:([0-9.]{7,15})", 1) If @error = 0 Then $iSearch = _ArraySearch($ClientList, $Exp[0]) If $iSearch <> -1 Then UDPCloseSocket($ClientList[$iSearch][0]) _ArrayDelete($ClientList, $iSearch) If Not IsArray($ClientList) Then Local $ClientList[1][2] $ClientList[0][0] = -1 $ClientList[0][1] = -1 GUICtrlSetData($Edit1, @CRLF & "Everyone has left you." & @CRLF & "Are you feeling lonely yet?" & @CRLF, "append") GUICtrlSetState($Edit1, $GUI_DISABLE) GUICtrlSetState($Input1, $GUI_DISABLE) Else GUICtrlSetData($Edit1, @CRLF & $Exp[0] & " left chat.", "append") EndIf _UpdateListView() EndIf EndIf $Exp = StringRegExp($data, "CH:([0-9.]{7,15}):(.*)", 1) If @error = 0 Then ConsoleWrite("Recieved(CH): " & $data & @CRLF) $fAllowSend = False GUICtrlSetData($Edit1, @CRLF & @CRLF & "Chat History From " & $Exp[0] & ":" & @CRLF & StringReplace(StringRegExpReplace($Exp[1], "([^/]/n)", @CRLF), "//n", "/n") & @CRLF, "append") $fAllowSend = True EndIf EndIf $RecvTimer = TimerInit() EndIf WEnd Func _UpdateListView() GUICtrlDelete($hListview) $hListview = GUICtrlCreateListView("#|IP", 290, 27, 155, 150) _GUICtrlListView_SetColumnWidth($hListview, 0, 25) _GUICtrlListView_SetColumnWidth($hListview, 1, 125) $IPList = "" For $x = 0 To UBound($ClientList) - 1 If $ClientList[$x][1] = -1 Then ContinueLoop GUICtrlCreateListViewItem($x + 1 & "|" & $ClientList[$x][1], $hListview) $IPList = "|" & $ClientList[$x][1] Next $IPList = StringTrimLeft($IPList, 1) EndFunc ;==>_UpdateListView Func _IsIPInList($sIP) $IPList = "" For $x = 0 To UBound($ClientList) - 1 $IPList &= "|" & $ClientList[$x][1] Next $IPList = StringTrimLeft($IPList, 1) Return StringInStr($IPList, $sIP) > 0 ; True or False EndFunc ;==>_IsIPInList Func Cleanup() GUIDelete() UDPCloseSocket($INsocket) UDPCloseSocket($SYSTEMsocket) If $OUTsocket Then UDPCloseSocket($OUTsocket) For $x = 0 To UBound($ClientList) - 1 If $ClientList[$x][0] = -1 Then ContinueLoop $OUTsocket = UDPOpen($ClientList[$x][1], 81) UDPSend($OUTsocket, "DEL:" & @IPAddress1) UDPCloseSocket($OUTsocket) UDPCloseSocket($ClientList[$x][0]) ConsoleWrite("Closed: " & $ClientList[$x][1] & ":80" & @CRLF) Next UDPShutdown() EndFunc ;==>Cleanup Updates: Various code improvements - by guiness
×
×
  • Create New...