40 posts in this topic
TCPStartup() ; TCPConnect('220.127.116.11', '80') Local $error = @error MsgBox(0, 'AutoIt Version: ' & @AutoItVersion, 'AutoIt Error: ' & $error & @CRLF & 'WSAError: ' & _WSAGetLastErrorEx() & @TAB) TCPShutDown() ; Func _WSAGetLastErrorEx() Local $a = DllCall('ws2_32.dll', 'int', 'WSAGetLastError') If @error Or Not IsArray($a) Then Return SetError(1, 0, 'FuncError -1') $a = DllCall('kernel32.dll', 'int', 'FormatMessage', 'int', 0x00001000, 'ptr', 0, 'int', $a, 'int', 0, 'str', 0, 'int', 2048, 'ptr', 0) If @error Or Not IsArray($a) Then Return SetError(1, 0, 'FuncError -2') Return $a & ' - ' & StringStripWS($a, 7) EndFunc Tested: autoit-v18.104.22.168, autoit-v22.214.171.124 and autoit-v126.96.36.199 beta on Win7.
Seems to have started with autoit-v188.8.131.52.
this is the first time to post a problem with autoit, I have been using it for more than 3 years but im still feel new
I have a VPS running online game ,
I'm making an program witch reads packets from server/client, first of all it reads size of the packet(it may be 1-5 bytes in size), and then reads what's left.
Problem: TCPRecv($socket,1,1) tooks really long to receive 1 byte, most of the time 100ms!
You can see packets here and how much time it took to read size of them(1-5 bytes, all of them are 1 byte in size): 0xAA63 (99.8802703210873ms) 0x53 (99.8829718030123ms) 0x2B (99.7435753356861ms) 0x4E (100.176352740059ms) I want to interrupt sometimes server or client, send packets, but I cannot send packets if server/client didn't get last packet. Sometimes packets are huge(16MB or even more), sometimes they are 2-6 bytes in size. I just don't want to receive everything and just send it. I want to see every packet, and collect data from these packets.
EDIT: I receive couple packets at the same time with TCPRecv to make it faster. I use TCPRecv($socket,10000,1). It made program a bit faster... But still, when receiving again these packets, it still tooks 100ms. It's still slow.
How to make TCPRecv($socket,1,1) faster? I don't need any error checking or etc., just to make it as fast as possible. (I only receive everything in hexadecimal)
I really need help with this... It's so slow and annoying!
This script is based on algorithm code from EnrMa.
Updated: January 07, 2017
Changes are in the script header.
POST is not working consistently in uploading files. AutoIt x64 does not work properly with this script.
If you are talking using text based protocols, Kip's TCP.au3 event driven UDF is great. But what happens if you want to talk to a 3rd party providers device/software that talks using binary format data in packet form? What if the packet size is variable? PTCP is a wrapper around Kip's TCP.au3 that lets you focus on dealing with the packets, rather than figuring out how to determine if there is a complete packet available etc.
For sending, you just send a binary string (the actual packet data)
For receiving, you just get a complete packet - even if the packet size is variable!
How? When you connect, you pass an AutoIt expression that tells PTCP how to tell if a packet is complete. For fixed sized packets, that's easy - just pass the number of bytes. For variable length packets, the expression can contain references to the packet data itself, as well as the number of bytes currently in the Rx buffer. This means you can specify the packet size as some combination of bytes in the packet.
An example might be: "($iAvail>7)?((BitAND(BinaryMid($aPacket,7,1), '0xff'))+(BitShift(BitAND(BinaryMid($aPacket,8,1),'0xff'),-8))+8):(0)"
This says: we need at least 8 bytes of the packet to know the packet size; once we have these 8 bytes, the packet size is stored in bytes 7 & 8 as little-endian (LSB first)
Other than the packetizing details, it's pretty much just Kip's event driven TCP code.
Hope you find it useful.