Sign in to follow this  
Followers 0
GTxFinish

Help: Client/Server

5 posts in this topic

Hey, im writing this Autoit Script (client and server) for remote control of the server through the network.

The server is hosting multiple dedicated servers, and the point of the script is to control say, map changes and settings changes via the client. So far, i've scripted a bit of a Quick GUI, and the GUI functions seems to work, and the server is currently configured to recieve the map name, and display it in a MsgBox.

Everything is working great, except for one thing. As soon as say someone closes their client, and then reopens it, and attempts to change a map, the server doesnt recieve the data sent. Its gotta be something to do with TCP, and something closing or me not reopening it. I dont know...thats why im here!

If someone has multiple computers, Please test out my Client/Server. Here's how to duplicate the problem.

First, change the IPs to fit your network, at the moment, they must be changed in the scripts (szIPADRESS).

Run the server first, then the client.

You'll see if you select a map, and hit "Change Map", the server will pop a message box with the map name.

You can do this as many times as you want, and it works.

Now close the client.

Then reopen it.

Try to change the map, and the server no longer pops a box.

What have I written Wrong?

Please assist,

Tucker

Ps: i've enclosed a .rar file with the script and the pictures directory, currently the script needs thsi directory to work properly (for map pictures upon selection). the scripts are also included.

Rar Link: (The Rar is ~50mb due to pictures enclosed, having to be .bmp are quite large)

http://turing.plymouth.edu/~gktucker/Script.rar

Code for each:

SERVER:

;SERVER!! Start Me First !!!!!!!!!!!!!!!
#include <GUIConstants.au3>

; Set Some reusable info
; Set your Public IP address (@IPAddress1) here.
Dim $szIPADDRESS = "5.70.18.61"
Dim $nPORT = 50000


; Start The TCP Services
;==============================================
TCPStartUp()

; Create a Listening "SOCKET".
;   Using your IP Address and Port 33891.
;==============================================
$MainSocket = TCPListen($szIPADDRESS, $nPORT)

; If the Socket creation fails, exit.
If $MainSocket = -1 Then Exit

; Initialize a variable to represent a connection
;==============================================
Dim $ConnectedSocket = -1


;Wait for and Accept a connection
;==============================================
Do
    $ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1


; Get IP of client connecting

Dim $msg, $recv
; GUI Message Loop
;==============================================
While 1

; Try to receive (up to) 2048 bytes
;----------------------------------------------------------------
    $recv = TCPRecv( $ConnectedSocket, 2048 )
; Update the edit control with what we have received
;----------------------------------------------------------------
    If $recv <> "" Then
        MsgBox(0,"SERVER",$recv)
    EndIf

WEnd

If $ConnectedSocket <> -1 Then TCPCloseSocket( $ConnectedSocket )

TCPShutDown()


; Function to return IP Address from a connected socket.
;----------------------------------------------------------------------
Func SocketToIP($SHOCKET)
    Local $sockaddr = DLLStructCreate("short;ushort;uint;char[8]")

    Local $aRet = DLLCall("Ws2_32.dll","int","getpeername","int",$SHOCKET, _
            "ptr",DLLStructGetPtr($sockaddr),"int_ptr",DLLStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DLLCall("Ws2_32.dll","str","inet_ntoa","int",DLLStructGetData($sockaddr,3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf

    $sockaddr = 0

    Return $aRet
EndFunc

CLIENT:

;; Tuck's RemoteGUI

#include <GUIConstants.au3>

GUICreate("CORE*Remote",768,455)

Global $defaultstatus = "Ready"
Global $status
Global $mapbmp
$filemenu = GUICtrlCreateMenu ("&File")
$helpmenu = GUICtrlCreateMenu ("?")
$infoitem = GUICtrlCreateMenuitem ("Info",$helpmenu)
$exititem = GUICtrlCreateMenuitem ("Exit",$filemenu)

;$separator1 = GUICtrlCreateMenuitem ("",$filemenu,2)   ; create a separator line

$viewmenu = GUICtrlCreateMenu("View",-1,1) ; is created before "?" menu
$viewstatusitem = GUICtrlCreateMenuitem ("Statusbar",$viewmenu)
GUICtrlSetState(-1,$GUI_CHECKED)

$statuslabel = GUICtrlCreateLabel ($defaultstatus,0,418,900,16,BitOr($SS_SIMPLE,$SS_SUNKEN))
$tab=GUICtrlCreateTab (10,10, 750,400)

$tab0=GUICtrlCreateTabitem ("UT2004")
;---------------------Tab 0---------------------------
$tab0combo=GUICtrlCreateCombo ("", 350,50,130,120)
GUICtrlSetData(-1,"AS-Convoy|AS-FallenCity|AS-Glacier|AS-Junkyard|AS-Mothership|AS-RobotFactory|BR-Anubis|BR-Bifrost|BR-BridgeOfFate|BR-Canyon|BR-Colossus|BR-DE-ElecFields|BR-Disclosure|BR-IceFields|BR-Serenity|BR-Skyline|BR-Slaughterhouse|BR-TwinTombs|CTF-1on1-Joust|CTF-AbsoluteZero|CTF-Avaris|CTF-BridgeOfFate|CTF-Chrome|CTF-Citadel|CTF-Colossus|CTF-DE-ElecFields|CTF-December|CTF-DoubleDamage|CTF-Face3|CTF-FaceClassic|CTF-Geothermal|CTF-Grassyknoll|CTF-Grendelkeep|CTF-January|CTF-LostFaith|CTF-Magma|CTF-Maul|CTF-Moondragon|CTF-Orbital2|CTF-Smote|CTF-TwinTombs|DM-1on1-Albatross|DM-1on1-Crash|DM-1on1-Desolation|DM-1on1-Idoma|DM-1on1-Irondust|DM-1on1-Mixer|DM-1on1-Roughinery|DM-1on1-Serpentine|DM-1on1-Spirit|DM-1on1-Squader|DM-1on1-Trite|DM-Antalus|DM-Asbestos|DM-Compressed|DM-Corrugation|DM-Curse4|DM-DE-Grendelkeep|DM-DE-Ironic|DM-DE-Osiris2|DM-Deck17|DM-DesertIsle|DM-Flux2|DM-Gael|DM-Gestalt|DM-Goliath|DM-HyperBlast2|DM-IceTomb|DM-Inferno|DM-Injector|DM-Insidious|DM-IronDeity|DM-Junkyard|DM-Leviathan|DM-Metallurgy|DM-Morpheus3|DM-Oceanic|DM-Phobos2|DM-Plunge|DM-Rankin|DM-Rrajigar|DM-Rustatorium|DM-Sulphur|DM-TokaraForest|DM-TrainingDay|DOM-Access|DOM-Aswan|DOM-Atlantis|DOM-Conduit|DOM-Core|DOM-Junkyard|DOM-Outrigger|DOM-Renascent|DOM-Ruination|DOM-ScorchedEarth|DOM-SepukkuGorge|DOM-Suntemple|ONS-ArcticStronghold|ONS-Crossfire|ONS-Dawn|ONS-Dria|ONS-Frostbite|ONS-Primeval|ONS-RedPlanet|ONS-Severance|ONS-Torlan", "AS-Convoy"); default AS-Convoy
$picture = GUICtrlCreatePic("Pictures\AS-Convoy.bmp",350,100,400,300)
$tab0label1=GUICtrlCreateLabel("Selected Map Preview: ",350,85)
$tab0label2=GUICtrlCreateLabel("Choose Map: ",350,35)
$tab0button1=GUICtrlCreateButton("Change Map",485,50,70,20)
;-----------------------------------------------------
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
$tab1=GUICtrlCreateTabitem ( "CS:S")
;---------------------Tab 1---------------------------

;-----------------------------------------------------

$tab2=GUICtrlCreateTabitem ("Advanced")
;---------------------Tab 2---------------------------

;-----------------------------------------------------
GUICtrlCreateTabitem ("")  ; end tabitem definitio
GUISetState ()
; Start The TCP Services
;==============================================
TCPStartUp()

; Set Some reusable info
;--------------------------
; Set $szIPADDRESS to wherever the SERVER is. We will change a PC name into an IP Address
Dim $szIPADDRESS = "5.70.18.61"
Dim $nPORT = 50000


; Initialize a variable to represent a connection
;==============================================
Dim $ConnectedSocket = -1


;Attempt to connect to SERVER at its IP and PORT 33891
;=======================================================
$ConnectedSocket = TCPConnect($szIPADDRESS,$nPORT)

Dim $szData
; If there is an error... show it
If @error Then
    GUIDelete()
    MsgBox(4112,"Error","TCPConnect failed with WSA error: " & @error)
; If there is no error
Else
;Loop forever asking for data to send to the SERVER
    While 1
            $msg = GUIGetMsg()
    
    If $msg = $viewstatusitem Then
        If BitAnd(GUICtrlRead($viewstatusitem),$GUI_CHECKED) = $GUI_CHECKED Then
            GUICtrlSetState($viewstatusitem,$GUI_UNCHECKED)
            GUICtrlSetState($statuslabel,$GUI_HIDE)
        Else
            GUICtrlSetState($viewstatusitem,$GUI_CHECKED)
            GUICtrlSetState($statuslabel,$GUI_SHOW)
        EndIf
    EndIf
    If $msg = $GUI_EVENT_CLOSE Or $msg = $exititem Then
        TCPCloseSocket($ConnectedSocket)
        TCPShutdown()
        ExitLoop
        EndIf
    If $msg = $infoitem Then MsgBox(0,"Server Information",$szIPADDRESS)
    If $msg = $tab0combo Then
            $mapbmp = GUICtrlRead($tab0combo)
        GUICtrlSetImage($picture,"Pictures\" & $mapbmp & ".bmp")
    EndIf
    
    If $msg = $tab0button1 Then
        TCPSend($ConnectedSocket,$mapbmp)
    EndIf
    WEnd
EndIf

GUIDelete()
TCPCloseSocket($ConnectedSocket)
TCPShutdown()
Exit

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Eehm...is it only me or is this topic fucked up ? Like formatting and such...

Edited by Helge

Share this post


Link to post
Share on other sites

if your computers are all on a network why are you using their public IP instead of the gateway network IP ?

Share this post


Link to post
Share on other sites

if your computers are all on a network why are you using their public IP instead of the gateway network IP ?

Its using Hamachi.

And the formatting looks fucked up, cause its a long, long Combo box.

Share this post


Link to post
Share on other sites

Its using Hamachi.

And the formatting looks fucked up, cause its a long, long Combo box.

Off your specific question, but to help with posting on the boards, you may look at Continuation Characters.

Example:

MsgBox(64, 'Info', 0 & _
1 & _
2 & _
3 & _
4 & _
5 & _
6 & _
7 & _
8 & _
9)
Will give you 0123456789, Easier to manage long strings, and debug situations easier.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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