Sign in to follow this  
Followers 0
SSJoco

Server/Client connection Little Help

4 posts in this topic

I tried to make a server/client application. The server run a game and accept some command from the client. It is working expect the server can't send back the Done message to the client. I managed to send back the first "connected" message, but the client do not show the next messages.

Any idea?

Server

CODE
#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

Global $mod

Global $ConnectedSocket

Global $Socket2

$IP=@IPAddress1

$Port=65432

$mod=0

$valasz=MsgBox(4, "CoD4 Server Mod", "Mod server?", 10)

If $valasz=6 Then $mod=1

CodRun()

#Region ### START Koda GUI section ### Form=E:\CD\Válogatás\Rendszer\AutoIt\--=Saját=--\Szerver\cod4 babysitter.kxf

$Form1_1 = GUICreate("CoD4 Babysitter Server 1.1", 283, 175, 322, 181)

$Label1 = GUICtrlCreateLabel("CoD4 Babysitter Server", 46, 16, 202, 24)

GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")

$exit = GUICtrlCreateButton("Kilép", 85, 108, 105, 41, 0)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

; Start The TCP Services

TCPStartUp()

; Create a Listening "SOCKET"

$MainSocket = TCPListen($IP, $Port, 100 )

If $MainSocket = -1 Then Exit

; look for client connection

While 1

$ConnectedSocket = TCPAccept( $MainSocket)

If $ConnectedSocket >= 0 Then

$recv = TCPRecv($ConnectedSocket, 128)

sleep(300)

If StringLen($recv) Then

If StringInStr($recv, "Connect:") Then

$recv = StringSplit($recv, ":")

$ip2 = $recv[2]

$Socket2 = TCPConnect($ip2, $Port)

$Label2 = GUICtrlCreateLabel($ip2, 85, 70, 80, 17, $SS_CENTER)

TCPSend($Socket2, "Connected...")

sleep(2000)

Valaszt()

EndIf

EndIf

EndIf

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

kilep()

Case $exit

kilep()

EndSwitch

Wend

Func Valaszt()

sleep(100)

$recv = TCPRecv($ConnectedSocket, 128)

While 1

$recv = TCPRecv($ConnectedSocket, 128)

Switch $recv

Case "mod"

$mod=1

Codrun()

TCPSend($Socket2, "ModWarfare")

Case "normal"

$mod=0

Codrun()

TCPSend($Socket2, "CoD4 elindítva")

Case "copy"

Copy()

TCPSend($Socket2, "Fájlok átmásolva")

Case "end"

TCPCloseSocket ($ConnectedSocket)

TCPCloseSocket ($Socket2)

GUICtrlDelete ($Label2)

exitloop

EndSwitch

WEnd

EndFunc

Func Codrun()

If WinExists ("CoD4 Console") Then

WinClose ("CoD4 Console")

WinWaitClose ("CoD4 Console")

EndIf

If $mod Then

Run ("iw3mp.exe")

EndFunc

Func Copy()

EndFunc

Func kilep()

TCPCloseSocket($ConnectedSocket)

TCPCloseSocket($Socket2)

TCPShutdown ( )

exit

EndFunc

';

Client

CODE
#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

Global $ConnectedSocket

Global $Connected2

$IP="192.168.2.60"

$Port=65432

$MyIP=@IPAddress1

#Region ### START Koda GUI section ###

$Form1_1 = GUICreate("CoD4 Babysitter Kliens 1.1", 283, 360, 322, 181)

$normal = GUICtrlCreateButton("Normal Mod", 81, 54, 129, 41, 0)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

$modd = GUICtrlCreateButton("ModWarfare", 81, 107, 129, 41, 0)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

$copy = GUICtrlCreateButton("Copy", 81, 165, 129, 41, 0)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

$Label1 = GUICtrlCreateLabel("CoD4 Babysitter Client", 46, 16, 199, 24)

GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")

$Label2 = GUICtrlCreateLabel("Messges", 86, 240, 118, 17, $SS_CENTER)

$exit = GUICtrlCreateButton("Kilép", 93, 292, 105, 41, 0)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

; Start The test

TCPStartUp()

$ConnectedSocket = TCPConnect($IP, $PORT)

If @error Then

MsgBox(4096, "Hiba :)", "TCPConnect hiba: " & @error)

EndIf

TCPSend($ConnectedSocket, "Connect:" & $MyIP)

; Create a Listening "SOCKET"

$MainSocket2 = TCPListen($MyIP, $Port, 100 )

If $MainSocket2 = -1 Then Exit

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $exit

TCPSend($ConnectedSocket, "end")

kilep()

Case $GUI_EVENT_CLOSE

TCPSend($ConnectedSocket, "end")

kilep()

Case $normal

TCPSend($ConnectedSocket, "normal")

Case $modd

TCPSend($ConnectedSocket, "mod")

Case $copy

TCPSend($ConnectedSocket, "copy")

EndSwitch

; look for client connection

$Connected2 = TCPAccept( $MainSocket2)

If $Connected2 >= 0 Then

$recv = TCPRecv($Connected2, 128)

GUICtrlDelete ( $Label2 )

$Label2 = GUICtrlCreateLabel($recv, 86, 240, 118, 17, $SS_CENTER)

GUISetState()

EndIf

WEnd

Func kilep()

TCPCloseSocket($ConnectedSocket)

sleep(300)

TCPCloseSocket($Connected2)

TCPShutdown ( )

exit

EndFunc;

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You only need to do the TCPAccept once then just receive messages, although the example from the Help Files shows differently.

CODE
#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

Global $ConnectedSocket

Global $Connected2

$IP="192.168.2.60"

$Port=65432

$MyIP=@IPAddress1

#Region ### START Koda GUI section ###

$Form1_1 = GUICreate("CoD4 Babysitter Kliens 1.1", 283, 360, 322, 181)

$normal = GUICtrlCreateButton("Normal Mod", 81, 54, 129, 41, 0)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

$modd = GUICtrlCreateButton("ModWarfare", 81, 107, 129, 41, 0)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

$copy = GUICtrlCreateButton("Copy", 81, 165, 129, 41, 0)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

$Label1 = GUICtrlCreateLabel("CoD4 Babysitter Client", 46, 16, 199, 24)

GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")

$Label2 = GUICtrlCreateLabel("Messges", 86, 240, 118, 17, $SS_CENTER)

$exit = GUICtrlCreateButton("Kilép", 93, 292, 105, 41, 0)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

; Start The test

TCPStartUp()

$ConnectedSocket = TCPConnect($IP, $Port)

If @error Then

MsgBox(4096, "Hiba ", "TCPConnect hiba: " & @error)

EndIf

TCPSend($ConnectedSocket, "Connect:" & $MyIP)

; Create a Listening "SOCKET"

$MainSocket2 = TCPListen($MyIP, $Port, 100 )

If $MainSocket2 = -1 Then Exit

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $exit

TCPSend($ConnectedSocket, "end")

kilep()

Case $GUI_EVENT_CLOSE

TCPSend($ConnectedSocket, "end")

kilep()

Case $normal

TCPSend($ConnectedSocket, "normal")

$Connected2 = TCPAccept( $MainSocket2)

Case $modd

TCPSend($ConnectedSocket, "mod")

$Connected2 = TCPAccept( $MainSocket2)

Case $copy

TCPSend($ConnectedSocket, "copy")

$Connected2 = TCPAccept( $MainSocket2)

EndSwitch

; look for client connection

$recv = TCPRecv($Connected2, 128)

If $recv <> "" Then GUICtrlSetData($Label2, $recv)

WEnd

Func kilep()

TCPCloseSocket($ConnectedSocket)

sleep(300)

TCPCloseSocket($Connected2)

TCPShutdown ( )

exit

EndFunc;

CODE
#include <ButtonConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

Global $mod

Global $ConnectedSocket

Global $Socket2

$IP=@IPAddress1

$Port=65432

$mod=0

$valasz=MsgBox(4, "CoD4 Server Mod", "Mod server?", 10)

If $valasz=6 Then $mod=1

CodRun()

#Region ### START Koda GUI section ### Form=E:\CD\Válogatás\Rendszer\AutoIt\--=Saját=--\Szerver\cod4 babysitter.kxf

$Form1_1 = GUICreate("CoD4 Babysitter Server 1.1", 283, 175, 322, 181)

$Label1 = GUICtrlCreateLabel("CoD4 Babysitter Server", 46, 16, 202, 24)

GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")

$exit = GUICtrlCreateButton("Kilép", 85, 108, 105, 41, 0)

GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

; Start The TCP Services

TCPStartUp()

; Create a Listening "SOCKET"

$MainSocket = TCPListen($IP, $Port, 100 )

If $MainSocket = -1 Then Exit

; look for client connection

While 1

$ConnectedSocket = TCPAccept( $MainSocket)

If $ConnectedSocket >= 0 Then

$recv = TCPRecv($ConnectedSocket, 128)

sleep(300)

If StringLen($recv) Then

If StringInStr($recv, "Connect:") Then

$recv = StringSplit($recv, ":")

$ip2 = $recv[2]

$Socket2 = TCPConnect($ip2, $Port)

$Label2 = GUICtrlCreateLabel($ip2, 85, 70, 80, 17, $SS_CENTER)

TCPSend($Socket2, "Connected...")

sleep(2000)

Valaszt()

EndIf

EndIf

EndIf

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

kilep()

Case $exit

kilep()

EndSwitch

Wend

Func Valaszt()

sleep(100)

While 1

$recv = TCPRecv($ConnectedSocket, 128)

Switch $recv

Case "mod"

$mod=1

Codrun()

TCPSend($Socket2, "ModWarfare")

Case "normal"

$mod=0

Codrun()

TCPSend($Socket2, "CoD4 elindítva")

Case "copy"

Copy()

TCPSend($Socket2, "Fájlok átmásolva")

Case "end"

TCPCloseSocket ($ConnectedSocket)

TCPCloseSocket ($Socket2)

GUICtrlDelete ($Label2)

exitloop

EndSwitch

WEnd

EndFunc

Func Codrun()

If WinExists ("CoD4 Console") Then

WinClose ("CoD4 Console")

WinWaitClose ("CoD4 Console")

EndIf

If $mod Then Run ("iw3mp.exe")

EndFunc

Func Copy()

EndFunc

Func kilep()

TCPCloseSocket($ConnectedSocket)

TCPCloseSocket($Socket2)

TCPShutdown ( )

exit

EndFunc

Edited by cartman380

Share this post


Link to post
Share on other sites

Thnx

Share this post


Link to post
Share on other sites

Thnx

NP :)

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