TCPRecv is slow!

4 posts in this topic

algiuxas 9

Hello everybody,
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)

Sign in

Similar Content

I have had several people ask for this, so I decided to work the algorithm for it and this is the result.
What is it?
A Gateway Proxy Sends and Receives Data Unmodified.https://en.wikipedia.org/wiki/Proxy_server
What is it used for?
You can use it as a gateway, relay or router between two known static IP addresses.
More information is in the header of the script.
Download: LocalGatewayProxy.au3
You will need WSA_NBTCP.au3 from here:https://www.autoitscript.com/forum/topic/191954-wsa_nbtcp-v100-udf/
If you have any questions or problems, let me know.

This script is based on algorithm code from EnrMa.
Updated: January 22, 2018
Made improvements. Changes are in the script header.
Known Issues: AutoIt x64 does not work properly with this script.
Download: LocalProxyServer_v1.00.zip

WSA_NBTCP.au3 (Windows Sockets API - Non-Blocking Transmission Control Protocol)
Version: 1.00
Type: UDF
This is an accumulation of WSA code from many sources and modified to suit myself.
These functions have been thoroughly tested using a Local Proxy Server, which
is about the most strenuous test you can use.
Includes my rendition of how a TCPRecv Timeout should work. Also includes a
timewait/timeout using Select for TCP Send, which works great for that function.
You will need a loop to use _WSA_TCPRecv(). An example will be forthcoming in a second post.
Functions:
#CURRENT_USER_FUNCTIONS
_WSA_Cleanup
_WSA_FormatMessage
_WSA_GetLastError
_WSA_TCPAccept
_WSA_TCPCloseSocket
_WSA_TCPConnect
_WSA_TCPListen
_WSA_TCPRecv
_WSA_TCPSend

AutoIt-SocketIo
Yep yep, this is pretty much an attempt to port the existing project's concept https://socket.io/ to AutoIt's Codebase. So i will not go in to so much detail.
This is how the communication is done http://i.imgur.com/0mMfsBD.png
Each client is isolated to the server http://i.imgur.com/rVO2LFb.png
Features
Easy API
VarType Translation (Example: If the server sends an int, the client will receive an int and vice versa)
Fully featured examples
Data encryption (Using Autoit's UDF Crypt.au3)
Limitations / Drawbacks
It is not possible to Broadcast/Emit objects
Only 1D-arrays are allowed to be Broadcasted/Emitted (2D arrays will probably never be supported)
Changelog
Version 1.5.0 (This update DOES NOT break scripts)
Added AutoIt like docs under Docs\. The docs are generated so its a 1 to 1 reflection of the UDF headers. Print of documentation
Added a production ready server example.
Added a new method: _Io_DevDebug which will display useful information when debugging.
Added a new method: _Io_SetMaxRecvPackageSize which defaults to whatever _Io_setRecvPackageSize is set to.
Added a new method: _Io_setOnPrefix which defaults to _On_
Added a new default client & server event called flood. Flood occurs when exceeding the $__g_io_nMaxPacketSize. $__g_io_nMaxPacketSize is set by _Io_SetMaxRecvPackageSize
Fixed the 16 parameter limit when sending data with _Io_Emit, _Io_Broadcast, _Io_BroadcastToAll and _Io_BroadcastToRoom. This works on the same premise that AutoIt's Call Does
Fixed a TRUNCATION problem when receiving packages which could cause crashes!
Fixed a programming error which caused $__g_ionPacketSize to reset to default 4096 if _Io_Connect or _Io_listenwere called after _Io_setRecvPackageSize
Fixed _Io_setEventPreScript and _Io_setEventPostScript They didnt work. Lol.
Changed how events are fired so the client cannot crash the server by sending the wrong number of parameters (This also allows for optional parameters on callbacks)
Changed _Io_On. The second parameter $fCallback can now be set to null. Doing this, the function assumes that the callback is: _On_<eventName>.
Changelog History
Api methods
Please see the docs provided
Default events
Server events
connection
Client events
banned
Server and Client events
disconnect
flood
View source on github

Hello all.
In case this is interesting few of you, I share my AMCP 2.1 protocol UDF in AutoIT. This protocol is used by CasparCG server, which is a Windows and Linux software used to play out professional graphics, audio and video to multiple outputs as a layerbased real-time compositor. It has been in 24/7 broadcast production since 2006. It's free and opensource.
The UDF I share allows communication between an AutoIt based client and the CasparCG, based on following documentation : http://casparcg.com/wiki/CasparCG_2.1_AMCP_Protocol
If you want more details on CasparCG : official WebSite or have a look to this video
I'm currently building a full Client based on AutoIt, with many features like drag-and-drop layers, but sadly I can't share it right now, might come later. Don't hesitate to ask questions if you have any or need a basic example.
The only requirement for this UDF is the other Event-driven TCP UDF by Kip