Jump to content

Another TCP server (written with my socket_UDF)


funkey
 Share

Recommended Posts

Hello, I just made another TCP server. I will use the server for data collection and a lot of clients can get the data from TCP. I now use it for UDP broadcast some devices to get their IP's. You can also use it for chat's.

It is very low level, but so you have more options than with the pure AutoIt functions.

Just start the server in SciTE to see the console outputs. Then you can start up to 63 clients to talk to the server.

I hope you like it.

Server script:

#include "socket_UDF.au3"
;funkey 2013.06.21

_WSAStartup()

Global $iSocket
Global $iReturn
Global $iPort = 20500
Global $sIP_Connected
Global $iPort_Connected
Global $tBuffer = DllStructCreate("char buffer[512]")


$iSocket = _socket($AF_INET, $SOCK_STREAM, $IPPROTO_TCP)
ConsoleWrite("Listen Socket: " & $iSocket & @CRLF)

Global $tReUse = DllStructCreate("BOOLEAN reuse")
DllStructSetData($tReUse, "reuse", True) ; enable reusing the same port
$iReturn = _setsockopt($iSocket, $SOL_SOCKET, $SO_REUSEADDR, $tReUse) ; set reusing option for the port
If $iReturn Then
ConsoleWrite("SetSockOpt error setting reusing the same port!. Windows Sockets Error Codes: " & _WSAGetLastError() & @CRLF)
EndIf

$iReturn = _bind($iSocket, @IPAddress1, $iPort) ;local IP-Address and port to use
If $iReturn Then
ConsoleWrite("Bind error: " & $iReturn & @CRLF) ; 0 is OK
EndIf

$iReturn = _listen($iSocket, 1)
If $iReturn Then
ConsoleWrite("Listen error: " & $iReturn & @CRLF) ; 0 is OK
EndIf

Global $iNewSocket
Global $tReadFds = DllStructCreate($tagFd_set)
Global $tReadFds_Copy = DllStructCreate($tagFd_set)
_FD_ZERO($tReadFds)
_FD_SET($iSocket, $tReadFds)
Global $iSocketMax = $iSocket
Global $iSocketNow
Global $sDataRcv

While 1

DllCall('ntdll.dll', 'none', 'RtlMoveMemory', 'struct*', $tReadFds_Copy, 'struct*', $tReadFds, 'ULONG_PTR', DllStructGetSize($tReadFds))

$iReturn = _select($iSocketMax + 1, $tReadFds_Copy, 2000) ;timeout 2 seconds
If _FD_ISSET($iSocket, $tReadFds_Copy) Then
$iNewSocket = _accept($iSocket, $sIP_Connected, $iPort_Connected)
_FD_SET($iNewSocket, $tReadFds)
_FD_SHOW($tReadFds)
If $iNewSocket > $iSocketMax Then $iSocketMax = $iNewSocket
ConsoleWrite("New connected socket: " & $iNewSocket & @TAB & "IP: " & $sIP_Connected & @TAB & "Port: " & $iPort_Connected & @LF)
EndIf

For $i = 2 To DllStructGetData($tReadFds, "fd_count")
$iSocketNow = DllStructGetData($tReadFds, "fd_array", $i)
If _FD_ISSET($iSocketNow, $tReadFds_Copy) Then
DllCall('ntdll.dll', 'none', 'RtlZeroMemory', 'struct*', $tBuffer, 'ULONG_PTR', DllStructGetSize($tBuffer))
If _recv($iSocketNow, $tBuffer) = $SOCKET_ERROR Then
_closesocket($iSocketNow)
_FD_CLR($iSocketNow, $tReadFds)
Else
$sDataRcv = DllStructGetData($tBuffer, 1)
ConsoleWrite("Data received: " & $sDataRcv & @LF)
If $sDataRcv == "CloseServer!" Then
ExitLoop 2
EndIf
EndIf
EndIf
Next

WEnd

For $i = 1 To DllStructGetData($tReadFds, "fd_count")
_closesocket(DllStructGetData($tReadFds, "fd_array", $i))
Next

_WSACleanup()


Func _FD_SHOW(ByRef $tFd_set)
For $i = 1 To DllStructGetData($tFd_set, "fd_count")
ConsoleWrite($i & ":" & @TAB & DllStructGetData($tFd_set, "fd_array", $i) & @LF)
Next
EndFunc ;==>_FD_SHOW

socket_UDF and example.rar

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

  • 4 months later...
  • 2 weeks later...

Hi funkey

nice,

thanks for sharing

....  I now use it for UDP broadcast some devices to get their IP's. ....

 

could you please post an example to achieve this?

thanks

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • 3 weeks later...

 

Hi funkey

 

nice,

thanks for sharing

 

 

could you please post an example to achieve this?

 

thanks

This depends on devices you have and is different for every kind.

I have scripts to list all 'Siemens Sentron devices' and another one to list all 'Moxa Serial Device Servers' in our network.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

For example I send a few characters via UDP broadcast on a specified port (that's why I build that UDF - AutoIt does not support this, or this is buggy) to my network. Only devices that wait for information on that port and that know the characters send the requested information back.

But what information do you want to get from what devices?

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

I do not know if it's possible, but i wonder if an unknown device that responds to a ping, can be asked to respond what type of device is himself, for example if it's a router or a network printer or something else?
or maybe is possible the opposite of this?.So that I can broadcast for specific devices types (network printers for example?) and get response from (all) that type of devices only?

Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

If think, that is not possible for all devices, but for some devices you could get the MAC address from IP address and then look what company made the device (for example use http://wintelguy.com/index.pl to find this out). Here is a script to receive the MAC address via ARP request:

#include "socket_UDF.au3"

_WSAStartup()

Global $MAC = _SendARP(@IPAddress1)
ConsoleWrite("Local MAC address: " & $MAC & @LF)
Global $MAC = _SendARP("192.168.3.4")
ConsoleWrite("Remote MAC address: " & $MAC & @LF)

_WSACleanup()

Func _SendARP($DestIP)
Local $DestAddress = _inet_addr($DestIP)
Local $tMacAddr = DllStructCreate("BYTE[8]")
Local $aRet = DllCall("Iphlpapi.dll", "DWORD", "SendARP", "ULONG", $DestAddress, "ULONG", 0, "struct*", $tMacAddr, "ULONG*", 8)
Local $sMAC = ""
Switch $aRet[0]
Case 0
For $i = 1 To $aRet[4] - 1
$sMAC &= Hex(DllStructGetData($tMacAddr, 1, $i), 2) & "-"
Next
$sMAC &= Hex(DllStructGetData($tMacAddr, 1, $i), 2)
Return $sMAC
Case 31
Return "ERROR_GEN_FAILURE"
Case 87
Return "ERROR_INVALID_PARAMETER"
Case 1784
Return "ERROR_INVALID_USER_BUFFER"
Case 67
Return "ERROR_BAD_NET_NAME"
Case 1168
Return "ERROR_NOT_FOUND"
EndSwitch
EndFunc

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

  • 2 years later...
  • 5 years later...

Thanks funkey for good UDF.
Sorry for bad english. I have a problem with socket_UDF. I don't know different of UDF and TCP from autoit but my script return different.

This is console return.

Quote

Socket: 704
Connect error: 0
Bytes sent: 478
Bytes received: -1
Data received: 
Rev:0xBA2508E9071AB425520408061001721F080A121BC490C4836E67206E68E1BAAD70207468C3A06E682063C3B46E6720FA01892508E8361283250AD1030A04082410000A04085410010A04085210000A04085310005208080F10ABE5ADDE03520E08D10F10FFFFFFFFFFFFFFFFFF01520E08E10F10FFFFFFFFFFFFFFFFFF015204082010005204084010005205089E011000520508A7011000520508A9011014520508B0011000520508A8011001520508B1011000520508AB011001520508B7011000520508CB011000520408481000520508CD0110005204080610015204080510005204083F10005A0608071080B5185A0508900110005A09082310E2BE88DBD92F5A04085210005A04085310005A0608AA0110D00F5A0508910110005A0508920110006A0B083911000000000000000072100809120C4E506C61793130353634373172330808122F68747470733A2F2F7374617469632E6E706C61792E6D6F62692F646C632F6176617461722F467265652F312E706E677204080D12007204081012007204080E12007204081912007204081A120072100851120C6E706C617931303536343731720408611200720408601200720508D3011200720508D4011200720508D501120072120815120E636F6D2E686474742E6E706C6179721F080A121BC490C4836E67206E68E1BAAD70207468C3A06E682063C3B46E6720CA010508D6011200CA0104083A12000A595204083D10005204084710005204083E1000520408481000520408201000520408401000520508B10110005204083F10005A080849108090FBD30962070842150000803FCA01120846120E0A0CF403D00FC03EA8C301F093090A5BFA0158086E12540A0C5204086F10005204087010010A0C5204086F10015204087010010A0C5204086F10025204087010010A0C5204086F10035204087010010A0C5204086F10045204087010000A0C5204086F10055204087010010A8705FA018305083C12FE040A660A04084410000A04084B10005204082010005204083D10005204083E10005204083F100052040840100052040841100052040845100A5A0908D701108090FBD3095A0808D8011080B8992962070842150000803F62070843150000803F6207084E15000000000A670A04084410000A04084B10015204082010015205083D10F4035204083E107D5204083F10015204084010005204084110055204084510145A0908D701108090FBD3095A0808D8011080F4EE0662070842150000C03F62070843150000C03F6207084E15000020410A680A04084410000A04084B10015204082010025205083D10D00F5205083E10F4035204083F100252040840100052040841100A5204084510325A0908D7011080D8F8BD0E5A0808D8011080F4EE066207084215000000406207084315000000406207084E15000070410A680A04084410000A04084B10015204082010035205083D10C03E5205083E10D00F5204083F100352040840100152040841100F5204084510645A0908D7011080A0F6A7135A0808D8011080F4EE066207084215000040406207084315000040406207084E150000A0410A6A0A04084410010A04084B10015204082010045206083D10A8C3015205083E10EA305204083F1004520408401002520408411014520508451096015A0908D7011080D0E7A3305A0808D8011080F4EE066207084215000080406207084315000080406207084E150000C8410A6B0A04084410010A04084B10015204082010055206083D10F093095206083E10E0A8015204083F100552040840100352040841101E5205084510F4035A0908D7011080D8C4BD755A0808D8011080F4EE0662070842150000A04062070843150000A0406207084E150000F0410A1F5204082E10005204082F100A520408331014520408201001FA0104082712000AC91A520508D4171000520508F2171002FA01AA


This is my script.

#include "socket_UDF.au3"

_WSAStartup()

Global $iSock = _socket($AF_INET, $SOCK_STREAM, $IPPROTO_TCP)
ConsoleWrite("Socket: " & $iSock & @CRLF)

Global $tTimeVal = DllStructCreate("DWORD timeout")
DllStructSetData($tTimeVal, "timeout", 5000) ; Timeout 200ms

$iSockError = _setsockopt($iSock, $SOL_SOCKET, $SO_RCVTIMEO, $tTimeVal) ; set Timeout for recv
If $iSockError Then
    ConsoleWrite("SetSockOpt error setting recv timeout!. Windows Sockets Error Codes: " & _WSAGetLastError() & @CRLF)
    _closesocket($iSock)
    TCPShutdown() ;WSACleanup
EndIf

;~ Global $iBind = _bind($iSock, @IPAddress1, 20000) ;local IP-Address and port to use
;~ ConsoleWrite("Bind error: " & $iBind & @CRLF) ; 0 is OK

Global $iConnect = _connect($iSock, "3.1.168.177", 7103)
ConsoleWrite("Connect error: " & $iConnect & @CRLF) ; 0 is OK

If $iConnect Then
    ConsoleWrite("Windows Sockets Error Codes: " & _WSAGetLastError() & @CRLF)
    _closesocket($iSock)
    TCPShutdown() ;WSACleanup
EndIf

Global $sToSend = "0xec0108900f1ae6010a0408131001520408031000520408051000720a08021206332e31342e31726c0814126865326130386133616162323432666562343638633862336433376434643432332362636131373139626339613034393032233837343236383937323130353632353233353632233030313031313030393331313433372330303a31453a45343a30303a36443a3637720508a501120072120815120e636f6d2e686474742e6e706c6179720408161200721a081712166656566a75705547536869647249796932746a774133720408181200720e088d0112094d6e63414844593536720508df011200"
Global $tSendBuffer = DllStructCreate("char[" & StringLen($sToSend) & "]")
DllStructSetData($tSendBuffer, 1, $sToSend)

Global $iSend = _send($iSock, $tSendBuffer)
ConsoleWrite("Bytes sent: " & $iSend & @CRLF)

Global $tRecvBuffer = DllStructCreate("char[64]")
Global $iRecv = _recv($iSock, $tRecvBuffer)
ConsoleWrite("Bytes received: " & $iRecv & @CRLF)

ConsoleWrite("Data received: " & DllStructGetData($tRecvBuffer, 1) & @CRLF) ;input1;OFF

_closesocket($iSock)
_WSACleanup()

TCPStartup()
Opt("TCPTimeout",5000)
$SK_2 = TCPConnect("3.1.168.177", 7103)
TCPSend($SK_2,$sToSend)
$Rev = TCPRecv($SK_2,10*1024)
ConsoleWrite("Rev:"&$Rev &@CRLF)
TCPCloseSocket($SK_2)
TCPShutdown()

 

Link to comment
Share on other sites

Hi VetlteV,

you prepare only 64 bytes for UDF _recv() and 10*1024 bytes for AutoIt internal TCPRecv().

Maybe this is the problem.

 

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Thanks for reply @funkey,

I tried again but the result is still the same.

I test again on another server and return the same result.
 

Quote

Socket: 692
Connect error: 0
Bytes sent: 48
Bytes received: 250
Data received: HTTP/1.1 200 OK
Date: Sat, 11 Dec 2021 07:33:00 GMT
Server: Apache
X-Powered-By: PHP/7.3.32
Upgrade: h2,h2c
Connection: Upgrade
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

d
11.28.88.76
0

---------------------Autoit TCP0----------------------------------
Rev:HTTP/1.1 200 OK
Date: Sat, 11 Dec 2021 07:33:00 GMT
Server: Apache
X-Powered-By: PHP/7.3.32
Upgrade: h2,h2c
Connection: Upgrade
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

d
11.28.88.76
0

#include "socket_UDF.au3"

_WSAStartup()

Global $iSock = _socket($AF_INET, $SOCK_STREAM, $IPPROTO_TCP)
ConsoleWrite("Socket: " & $iSock & @CRLF)

Global $tTimeVal = DllStructCreate("DWORD timeout")
DllStructSetData($tTimeVal, "timeout", 5000) ; Timeout 200ms

$iSockError = _setsockopt($iSock, $SOL_SOCKET, $SO_RCVTIMEO, $tTimeVal) ; set Timeout for recv
If $iSockError Then
    ConsoleWrite("SetSockOpt error setting recv timeout!. Windows Sockets Error Codes: " & _WSAGetLastError() & @CRLF)
    _closesocket($iSock)
    TCPShutdown() ;WSACleanup
EndIf

;~ Global $iBind = _bind($iSock, @IPAddress1, 20000) ;local IP-Address and port to use
;~ ConsoleWrite("Bind error: " & $iBind & @CRLF) ; 0 is OK

Global $iConnect = _connect($iSock, "184.168.101.36", 80)
ConsoleWrite("Connect error: " & $iConnect & @CRLF) ; 0 is OK

If $iConnect Then
    ConsoleWrite("Windows Sockets Error Codes: " & _WSAGetLastError() & @CRLF)
    _closesocket($iSock)
    TCPShutdown() ;WSACleanup
EndIf

Global $sToSend = "GET /getip.php HTTP/1.1" & @CRLF & "Host: updatevng.com" & @CRLF & @CRLF
Global $tSendBuffer = DllStructCreate("char[" & StringLen($sToSend) & "]")
DllStructSetData($tSendBuffer, 1, $sToSend)

Global $iSend = _send($iSock, $tSendBuffer)
ConsoleWrite("Bytes sent: " & $iSend & @CRLF)

Global $tRecvBuffer = DllStructCreate("char["&10*1024&"]")
Global $iRecv = _recv($iSock, $tRecvBuffer)
ConsoleWrite("Bytes received: " & $iRecv & @CRLF)

ConsoleWrite("Data received: " & DllStructGetData($tRecvBuffer, 1) & @CRLF) ;input1;OFF

_closesocket($iSock)
_WSACleanup()

TCPStartup()
Opt("TCPTimeout",5000)
$SK_2 = TCPConnect("184.168.101.36", 80)
TCPSend($SK_2,$sToSend)
$Rev = TCPRecv($SK_2,10*1024)
ConsoleWrite("Rev:"&$Rev &@CRLF)
TCPCloseSocket($SK_2)
TCPShutdown()

 

Link to comment
Share on other sites

For me it works, maybe I have another version of the socket_UDF.

See attached.

socket_UDF.au3

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

I just took your code....

 

 

Console output:

Socket: 632
Connect error: 0
Bytes sent: 48
Bytes received: 227
Data received: HTTP/1.1 200 OK
Date: Sat, 11 Dec 2021 11:55:43 GMT
Server: Apache
X-Powered-By: PHP/7.3.32
Upgrade: h2,h2c
Connection: Upgrade
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8


Rev:HTTP/1.1 200 OK
Date: Sat, 11 Dec 2021 11:55:43 GMT
Server: Apache
X-Powered-By: PHP/7.3.32
Upgrade: h2,h2c
Connection: Upgrade
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

 

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Oh no it's not like that.

Host need test.

Global $iConnect = _connect($iSock, "3.1.168.177", 7103)

Data to send

Global $sToSend = "0xec0108900f1ae6010a0408131001520408031000520408051000720a08021206332e31342e31726c0814126865326130386133616162323432666562343638633862336433376434643432332362636131373139626339613034393032233837343236383937323130353632353233353632233030313031313030393331313433372330303a31453a45343a30303a36443a3637720508a501120072120815120e636f6d2e686474742e6e706c6179720408161200721a081712166656566a75705547536869647249796932746a774133720408181200720e088d0112094d6e63414844593536720508df011200"

And result need or like that.

0xBA2508E9071AB425520408061001721F080A121BC490C4836E67206E68E1BAAD70207468C3A06E682063C3B46E6720FA01892508E8361283250AD1030A04082410000A04085410010A04085210000A04085310005208080F10ABE5ADDE03520E08D10F10FFFFFFFFFFFFFFFFFF01520E08E10F10FFFFFFFFFFFFFFFFFF015204082010005204084010005205089E011000520508A7011000520508A9011014520508B0011000520508A8011001520508B1011000520508AB011001520508B7011000520508CB011000520408481000520508CD0110005204080610015204080510005204083F10005A0608071080B5185A0508900110005A09082310E2BE88DBD92F5A04085210005A04085310005A0608AA0110D00F5A0508910110005A0508920110006A0B083911000000000000000072100809120C4E506C61793130353634373172330808122F68747470733A2F2F7374617469632E6E706C61792E6D6F62692F646C632F6176617461722F467265652F312E706E677204080D12007204081012007204080E12007204081912007204081A120072100851120C6E706C617931303536343731720408611200720408601200720508D3011200720508D4011200720508D501120072120815120E636F6D2E686474742E6E706C6179721F080A121BC490C4836E67206E68E1BAAD70207468C3A06E682063C3B46E6720CA010508D6011200CA0104083A12000A595204083D10005204084710005204083E1000520408481000520408201000520408401000520508B10110005204083F10005A080849108090FBD30962070842150000803FCA01120846120E0A0CF403D00FC03EA8C301F093090A5BFA0158086E12540A0C5204086F10005204087010010A0C5204086F10015204087010010A0C5204086F10025204087010010A0C5204086F10035204087010010A0C5204086F10045204087010000A0C5204086F10055204087010010A8705FA018305083C12FE040A660A04084410000A04084B10005204082010005204083D10005204083E10005204083F100052040840100052040841100052040845100A5A0908D701108090FBD3095A0808D8011080B8992962070842150000803F62070843150000803F6207084E15000000000A670A04084410000A04084B10015204082010015205083D10F4035204083E107D5204083F10015204084010005204084110055204084510145A0908D701108090FBD3095A0808D8011080F4EE0662070842150000C03F62070843150000C03F6207084E15000020410A680A04084410000A04084B10015204082010025205083D10D00F5205083E10F4035204083F100252040840100052040841100A5204084510325A0908D7011080D8F8BD0E5A0808D8011080F4EE066207084215000000406207084315000000406207084E15000070410A680A04084410000A04084B10015204082010035205083D10C03E5205083E10D00F5204083F100352040840100152040841100F5204084510645A0908D7011080A0F6A7135A0808D8011080F4EE066207084215000040406207084315000040406207084E150000A0410A6A0A04084410010A04084B10015204082010045206083D10A8C3015205083E10EA305204083F1004520408401002520408411014520508451096015A0908D7011080D0E7A3305A0808D8011080F4EE066207084215000080406207084315000080406207084E150000C8410A6B0A04084410010A04084B10015204082010055206083D10F093095206083E10E0A8015204083F100552040840100352040841101E5205084510F4035A0908D7011080D8C4BD755A0808D8011080F4EE0662070842150000A04062070843150000A0406207084E150000F0410A1F5204082E10005204082F100A520408331014520408201001FA0104082712000AC91A520508D4171000520508F2171002FA01AA

 

Link to comment
Share on other sites

So you need to declare the data as binary. The inbuild function automatically detects it.

 

#include "socket_UDF.au3"

_WSAStartup()

Global $iSock = _socket($AF_INET, $SOCK_STREAM, $IPPROTO_TCP)
ConsoleWrite("Socket: " & $iSock & @CRLF)

Global $tTimeVal = DllStructCreate("DWORD timeout")
DllStructSetData($tTimeVal, "timeout", 5000) ; Timeout 200ms

$iSockError = _setsockopt($iSock, $SOL_SOCKET, $SO_RCVTIMEO, $tTimeVal) ; set Timeout for recv
If $iSockError Then
    ConsoleWrite("SetSockOpt error setting recv timeout!. Windows Sockets Error Codes: " & _WSAGetLastError() & @CRLF)
    _closesocket($iSock)
    TCPShutdown() ;WSACleanup
EndIf

Global $iConnect = _connect($iSock, "184.168.101.36", 80)
ConsoleWrite("Connect error: " & $iConnect & @CRLF) ; 0 is OK

If $iConnect Then
    ConsoleWrite("Windows Sockets Error Codes: " & _WSAGetLastError() & @CRLF)
    _closesocket($iSock)
    TCPShutdown() ;WSACleanup
EndIf

;~ Global $sToSend = "GET /getip.php HTTP/1.1" & @CRLF & "Host: updatevng.com" & @CRLF & @CRLF
;~ Global $bToSend = Binary($sToSend)
;~ ConsoleWrite($bToSend & @CRLF)

Global $bToSend = Binary("0xec0108900f1ae6010a0408131001520408031000520408051000720a08021206332e31342e31726c0814126865326130386133616162323432666562343638633862336433376434643432332362636131373139626339613034393032233837343236383937323130353632353233353632233030313031313030393331313433372330303a31453a45343a30303a36443a3637720508a501120072120815120e636f6d2e686474742e6e706c6179720408161200721a081712166656566a75705547536869647249796932746a774133720408181200720e088d0112094d6e63414844593536720508df011200")


;~ Global $tSendBuffer = DllStructCreate("char[" & StringLen($sToSend) & "]")
Global $tSendBuffer = DllStructCreate("byte[" & BinaryLen($bToSend) & "]")
;~ DllStructSetData($tSendBuffer, 1, $sToSend)
DllStructSetData($tSendBuffer, 1, $bToSend)

Global $iSend = _send($iSock, $tSendBuffer)
ConsoleWrite("Bytes sent: " & $iSend & @CRLF)

Global $tRecvBuffer = DllStructCreate("char["&10*1024&"]")
Global $iRecv = _recv($iSock, $tRecvBuffer)
ConsoleWrite("Bytes received: " & $iRecv & @CRLF)

ConsoleWrite("Data received: " & DllStructGetData($tRecvBuffer, 1) & @CRLF)

_closesocket($iSock)
_WSACleanup()

 

 

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

You are welcome!

Can you tell me why you want to use this UDF instead of the standard functions?

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

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

×
×
  • Create New...