haber mi intencion era crear un programa para transmitir imagenes por tcp, por aora e provado con archivos.txt y va pero no kon imagenes!
aqui el codigo que funciona con lor arxivos txt(para intentar transmitir imagenes lo k ago es cambiar la direccion del arxivo por el de una imagen:
CLIENTE
Código: Seleccionar todo
#include <Inet.au3>
Opt('MustDeclareVars', 1)
;==============================================
;==============================================
;CLIENT! Start Me after starting the SERVER!!!!!!!!!!!!!!!
;==============================================
;==============================================
Example()
Func Example()
; Set Some reusable info
;--------------------------
Local $ConnectedSocket, $szData, $arsivo
; 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 = "127.0.0.1"
Local $nPORT = 33891
; 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
;Loop forever asking for data to send to the SERVER
; data to transmit convertido a binario kon el 16
$arsivo = FileOpen(@MyDocumentsDir & "\ip.txt",16)
$szData = FileRead($arsivo)
; If they cancel the InputBox or leave it blank we exit our forever loop
If @error Or $szData = "" Then Exit
; We should have data in $szData... lets attempt to send it through our connected socket.
TCPSend($ConnectedSocket, $szData)
; If the send failed with @error then the socket has disconnected
;----------------------------------------------------------------
If @error Then Exit
EndIf
EndFunc ;==>Example
Código: Seleccionar todo
#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
;============================================== ;==============================================
;============================================== ;==============================================
;SERVER!! Start Me First !!!!!!!!!!!!!!! ;SERVER!! iniciame primero !!!!!!!!!!!!!!
;============================================== ;==============================================
;============================================== ;==============================================
Example()
Func Example()
; Set Some reusable info
; Set your Public IP address (@IPAddress1) here.
; Local $szServerPC = @ComputerName
; Local $szIPADDRESS = TCPNameToIP($szServerPC) ;nombre tcp a ip
Local $szIPADDRESS = "127.0.0.1"
Local $nPORT = 33891
Local $MainSocket, $GOOEY, $edit, $ConnectedSocket, $szIP_Accepted
Local $msg, $recv
local $lolix
; Start The TCP Services
;============================================== ;==============================================
TCPStartup()
; Create a Listening "SOCKET". ;creando un hueco o agujero que escuche
; Using your IP Address and Port 33891. ; usando tu IP y el puerto 33891
;============================================== ;==============================================
$MainSocket = TCPListen($szIPADDRESS, $nPORT)
; If the Socket creation fails, exit. ; si la creacion del hueco falla sale del programa
If $MainSocket = -1 Then Exit
; Initialize a variable to represent a connection ; iniciando una variable para representar una conexion
;============================================== ;==============================================
$ConnectedSocket = -1
;Wait for and Accept a connection ;esperando a aceptar una conexion
;============================================== ;==============================================
Do
$ConnectedSocket = TCPAccept($MainSocket)
Until $ConnectedSocket <> -1
; Get IP of client connecting ; cogiendo IP de el ordenador conectado
$szIP_Accepted = SocketToIP($ConnectedSocket)
; GUI Message Loop
;==============================================
While 1
; Try to receive (up to) 2048 bytes
;----------------------------------------------------------------
$recv = TCPRecv($ConnectedSocket, 248)
; If the receive failed with @error then the socket has disconnected
;----------------------------------------------------------------
If @error Then ExitLoop
; Update the edit control with what we have received
;----------------------------------------------------------------
If $recv <> "" Then
$lolix = Fileopen("C:\ola.txt",9)
FileWrite($lolix,$recv)
FileClose($lolix)
EndIf
WEnd
If $ConnectedSocket <> -1 Then TCPCloseSocket($ConnectedSocket)
TCPShutdown()
EndFunc ;==>Example
; Function to return IP Address from a connected socket. <-<-<-<-<-<- MUY INTERESANTE!!!!! COGER LA IP DEL CONECTADO
;----------------------------------------------------------------------
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