Page 1 sur 1
[R] Client et serveur fonctionnel 1 fois sur 3.
Posté : mar. 15 mars 2011 10:42
par Kinsuke
Bonjour, j'aimerai comprendre pourquoi ces scriptes ne fonctionnent qu'une foie sur trois.
► Afficher le texteClient
Code : Tout sélectionner
#include <WindowsConstants.au3>
#include <Inet.au3>
$IP_P=_GetIP()
$IP_SERVEUR = "XXX.XXX.X.XXX"
Local $SocketEnvoi , $port=16523
$SocketEnvoi = TCPConnect($IP_SERVEUR,$port)
$Fonction = "WinGetTitle"
$Title = WinGetTitle("[active]")
TCPSend($SocketEnvoi, $Fonction&"²"&$Title)
► Afficher le texteServeur
Code : Tout sélectionner
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ###
Global $Fenetre = GUICreate("Serveur de récéption", 524, 158, 192, 124)
Global $Zone_Edit = GUICtrlCreateEdit("", 0, 0, 521, 153)
GUICtrlSetData(-1, "")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$IP_SERVEUR ="XXX.XXX.X.XXX"
$port = 16523
while 1
TCPStartup()
$MainSocket = TCPlisten($IP_SERVEUR,$port,10000)
$Socket_receptrice = -1
do
$Socket_receptrice = TCPAccept($MainSocket)
$msg = GUIGetMsg()
if $msg = $GUI_EVENT_CLOSE then Exit
until $Socket_receptrice <> -1
$msg = GUIGetMsg()
if $msg = $GUI_EVENT_CLOSE then Exit
$data=TCPRecv($Socket_receptrice,4096)
$envoie = StringSplit($data,"²")
If $envoie <> "" then
if $envoie[1]="WinGetTitle" Then
GUICtrlSetData($Zone_Edit, $envoie[2])
endIF
endIF
TCPShutdown()
WEnd
Re: [..] Client et serveur fonctionnel 1 fois sur 3.
Posté : mar. 15 mars 2011 12:40
par Tlem
Re: [..] Client et serveur fonctionnel 1 fois sur 3.
Posté : mar. 15 mars 2011 17:16
par Kinsuke
Je ne sais pas si c'est ce à quoi tu voulais me mener mais en tout cas ça fonctionne :
► Afficher le texteServeur
Code : Tout sélectionner
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ###
Global $Fenetre = GUICreate("Serveur", 524, 158, 192, 124)
Global $Zone_Edit = GUICtrlCreateEdit("", 0, 0, 521, 153)
GUICtrlSetData(-1, "")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
while 1
$IP_SERVEUR ="XXX.XXX.X.XXX"
$port = 16523
TCPStartup()
$MainSocket = TCPlisten($IP_SERVEUR,$port,10000)
$Socket_receptrice = -1
do
$Socket_receptrice = TCPAccept($MainSocket)
$msg = GUIGetMsg()
if $msg = $GUI_EVENT_CLOSE then Exit
until $Socket_receptrice <> -1
$msg = GUIGetMsg()
if $msg = $GUI_EVENT_CLOSE then Exit
$data=TCPRecv($Socket_receptrice,4096)
$envoie = StringSplit($data,"²")
If $envoie <> "" then
if $envoie[1]="WinGetTitle" Then
GUICtrlSetData($Zone_Edit, $envoie[2])
endIF
endIF
TCPShutdown()
WEnd
Merci
Re: [R] Client et serveur fonctionnel 1 fois sur 3.
Posté : mar. 15 mars 2011 21:00
par Tlem
Si ca fonctionne, c'est déjà ca ...
Moi je voyais plutôt quelque chose dans ce genre :
► Afficher le texte
Code : Tout sélectionner
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $IP_SERVEUR = "192.168.1.10"
Global $port = 16523
Global $MainSocket, $Socket_receptrice
Global $Fenetre = GUICreate("Serveur", 524, 158, 192, 124)
Global $Zone_Edit = GUICtrlCreateEdit("", 0, 0, 521, 153)
GUICtrlSetData(-1, "")
GUISetState(@SW_SHOW)
_InitTCP()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case Else
Local $Socket_receptrice = TCPAccept($MainSocket)
If $Socket_receptrice <> -1 Then
Local $data = TCPRecv($Socket_receptrice, 4096)
Local $envoie = StringSplit($data, "²")
If $envoie <> "" Then
If $envoie[1] = "WinGetTitle" Then GUICtrlSetData($Zone_Edit, $envoie[2])
EndIf
TCPShutdown()
_InitTCP()
EndIf
EndSwitch
WEnd
Func _InitTCP()
TCPStartup()
$MainSocket = TCPlisten($IP_SERVEUR,$port,10000)
$Socket_receptrice = -1
EndFunc
Je ne sais pas si ce code fonctionne, mais il me parait plus clair et plus logique.
