Jump to content

how to use tcp send this


itljl
 Share

Recommended Posts

Thanks for you read this topic,i am english is bad

I want use tcp send desktop images ,and no use file

----------------------

TCP send File Example

----------------------

$S_ip = InputBox("please input ipaddress", "please input ipaddress", @IPAddress1)

$S_File = @ScriptDir & "\S.jpg"

$S_Prot = 65432

TCPStartup()

$socket = TCPConnect($S_ip, $S_Prot)

If $socket = -1 Then

Return "error: " & @error

Exit

EndIf

$File = FileOpen($S_File, 16)

If $File = -1 Then Return "2 open file error"

While 1

$fdata = FileRead($File, 1024 * 1000)

If @error = -1 Then ExitLoop

TCPSend($socket, $fdata)

WEnd

------------------------

how to this?

------------------------

$S_ip = InputBox("please input ipaddress", "please input ipaddress", @IPAddress1)

$S_File = @ScriptDir & "\S.jpg"

$S_Prot = 65432

TCPStartup()

$socket = TCPConnect($S_ip, $S_Prot)

If $socket = -1 Then

Return "error: " & @error

Exit

EndIf

$HBITMAP = _ScreenCapture_Capture(""")

;how to this? i don't want make file ---> _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image1.jpg")

While 1

TCPSend($socket, $HBITMAP)

WEnd

Link to comment
Share on other sites

#include <GDIPlus.au3>
#include <Memory.au3>
#include <ScreenCapture.au3>
Opt("MustDeclareVars", 1)

_GDIPlus_Startup()

Local $hBmp = _ScreenCapture_Capture()
Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
_WinAPI_DeleteObject($hBmp)

Local $sEncoderCLSID = _GDIPlus_EncodersGetCLSID("jpg")
Local $tEncoderCLSID = _WinAPI_GUIDFromString($sEncoderCLSID)
Local $pEncoderCLSID = DllStructGetPtr($tEncoderCLSID)
Local $pStream = _WinAPI_CreateStreamOnHGlobal(0)
_GDIPlus_ImageSaveToStream($hBitmap, $pStream, $pEncoderCLSID)
_GDIPlus_BitmapDispose($hBitmap)

Local $hMem = _WinAPI_GetHGlobalFromStream($pStream)
Local $iSize = _MemGlobalSize($hMem)
Local $pMem = _MemGlobalLock($hMem)
Local $tData = DllStructCreate("byte[" & $iSize & "]", $pMem)
Local $xData = DllStructGetData($tData, 1)
_MemGlobalFree($hMem)

Local $S_ip = InputBox("please input ipaddress", "please input ipaddress", @IPAddress1)
Local $S_Port = 65432

TCPStartup()
Local $socket = TCPConnect($S_ip, $S_Port)
If $socket <> -1 Then

    For $i = 0 To Int($iSize / 65536)
        TCPSend($socket, BinaryMid($xData, $i * 65536 + 1, 65536))
    Next
    TCPCloseSocket($socket)

EndIf

TCPShutdown()
_GDIPlus_Shutdown()

Func _GDIPlus_ImageSaveToStream($hImage, $pStream, $pEncoder, $pParams = 0)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSaveImageToStream", "ptr", $hImage, "ptr", $pStream, "ptr", $pEncoder, "ptr", $pParams)

    If @error Then Return SetError(1, 0, 0)
    Return SetError($aResult[0] <> 0, 0, $aResult[0] = 0)
EndFunc

Func _WinAPI_CreateStreamOnHGlobal($hGlobal, $fDeleteOnRelease = 1)
    Local $aResult = DllCall("ole32.dll", "uint", "CreateStreamOnHGlobal", "ptr", $hGlobal, "bool", $fDeleteOnRelease, "ptr*", 0)

    If @error Or $aResult[0] Then Return SetError(1, 0, 0)
    Return $aResult[3]
EndFunc

Func _WinAPI_GetHGlobalFromStream($pStream)
    Local $aResult = DllCall("ole32.dll", "uint", "GetHGlobalFromStream", "ptr", $pStream, "ptr*", 0)

    If @error Or $aResult[0] Then Return SetError(1, 0, 0)
    Return $aResult[2]
EndFunc

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...