Déjà fait, c'est pas si mal que ça.Iste a écrit :Sinon, 'suffit' d'avoir un server central.
Un pc constamment connecté ou bien une page php peut faire l'affaire, mais on y perd beaucoup en vitesse :/
Sinon voila pour vous bande de flémards!!! ( j'ai enfin piger le truc ^^ )
Serveur central
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
;==============================================
;==============================================
;SERVER!! Start Me First !!!!!!!!!!!!!!!
;==============================================
;==============================================
Example()
Func Example()
; Set Some reusable info
; Set your Public IP address (@IPAddress1) here.
; Local $szServerPC = @ComputerName
; Local $szIPADDRESS = TCPNameToIP($szServerPC)
Local $szIPADDRESS = @IPAddress1
Local $nPORT = 5552
Local $MainSocket, $GOOEY, $edit, $ConnectedSocket, $szIP_Accepted
Local $msg, $recv
; Start The TCP Services
;==============================================
TCPStartup()
; Create a Listening "SOCKET".
; Using your IP Address and Port 33891.
;==============================================
$MainSocket = TCPListen($szIPADDRESS, $nPORT)
If @error Then
MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error)
; If there is no error loop an inputbox for data
; to send to the SERVER.
EndIf
; If the Socket creation fails, exit.
If $MainSocket = -1 Then Exit
; Create a GUI for messages
;==============================================
$GOOEY = GUICreate("My Server (IP: " & $szIPADDRESS & ")", 300, 300)
$edit = GUICtrlCreateEdit("", 10, 10, 280, 180)
$input = GUICtrlCreateInput("",10,230,280,25)
$buttonsend=GUICtrlCreateButton("Envoyer",100,260,100,25)
GUISetState()
; Initialize a variable to represent a connection
;==============================================
$ConnectedSocket = -1
;Wait for and Accept a connection
;==============================================
Do
$ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1
; Get IP of client connecting
$szIP_Accepted = SocketToIP($ConnectedSocket)
; GUI Message Loop
;==============================================
While 1
$msg = GUIGetMsg()
; GUI Closed
;--------------------
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
If $msg = $buttonsend Then
GUICtrlSetData($edit,GUICtrlRead($edit)&"Moi > "&GUICtrlRead($input)&@crLF)
TCPSend($ConnectedSocket,GUICtrlRead($input))
GUICtrlSetData($input,"")
EndIf
; Try to receive (up to) 2048 bytes
;----------------------------------------------------------------
$recv = TCPRecv($ConnectedSocket, 2048)
; If the receive failed with @error then the socket has disconnected
;----------------------------------------------------------------
; Update the edit control with what we have received
;----------------------------------------------------------------
If $recv <> "" Then GUICtrlSetData($edit, _
$szIP_Accepted & " > " & $recv & @CRLF & GUICtrlRead($edit))
WEnd
If $ConnectedSocket <> -1 Then TCPCloseSocket($ConnectedSocket)
TCPShutdown()
EndFunc ;==>Example
; Function to return IP Address from a connected socket.
;----------------------------------------------------------------------
Func SocketToIP($SHOCKET)
Local $sockaddr, $aRet
$sockaddr = DllStructCreate("short;ushort;uint;char[8]")
$aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, _
"ptr", DllStructGetPtr($sockaddr), "int*", 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 ;==>SocketToIP
Client :
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
;==============================================
;==============================================
;CLIENT! Start Me after starting the SERVER!!!!!!!!!!!!!!!
;==============================================
;==============================================
Example()
Func Example()
; Set Some reusable info
;--------------------------
Local $ConnectedSocket, $szData
; Set $szIPADDRESS to wherever the SERVER is. We will change a PC name into an IP Address
; Local $szServerPC = @ComputerName
; Local $szIPADDRESS = TCPNameToIP($szServerPC)
Local $szIPADDRESS = InputBox("Entrer l'ip du serveur"," ","")
Local $nPORT = 5552
; Start The TCP Services
;==============================================
TCPStartup()
; Initialize a variable to represent a connection
;==============================================
$ConnectedSocket = -1
;Attempt to connect to SERVER at its IP and PORT 33891
;=======================================================
$ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT)
; If there is an error... show it
If @error Then
MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error)
; If there is no error loop an inputbox for data
; to send to the SERVER.
Else
$GOOEY = GUICreate("My Client (IP: " & $szIPADDRESS & ")", 300, 300)
$edit = GUICtrlCreateEdit("", 10, 10, 280, 180)
$input = GUICtrlCreateInput("",10,230,280,25)
$buttonsend=GUICtrlCreateButton("Envoyer",100,260,100,25)
GUISetState()
;Loop forever asking for data to send to the SERVER
While 1
$msg = GUIGetMsg()
; InputBox for data to transmit
If $msg = $buttonsend Then
GUICtrlSetData($edit,GUICtrlRead($edit)&"Moi > "&GUICtrlRead($input)&@crLF)
TCPSend($ConnectedSocket, GUICtrlRead($input))
GUICtrlSetData($input,"")
EndIf
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
$recv = TCPRecv($ConnectedSocket, 2048)
If $recv <> "" Then GUICtrlSetData($edit, _
"Server > " & $recv & @CRLF & GUICtrlRead($edit))
; If they cancel the InputBox or leave it blank we exit our forever loop
; We should have data in $szData... lets attempt to send it through our connected socket.
; If the send failed with @error then the socket has disconnected
;----------------------------------------------------------------
If @error Then ExitLoop
WEnd
EndIf
EndFunc ;==>Example
J'ai coder ça en 10 minutes donc pas trop de méchanceté SVP ^^
( Le pc qui exécute le serveur principal doit avoir le port 5552 TCP ouvert sur le routeur )