Faster TCPSockets

I looked through the RawSocketsMBS docs and really couldn’t see any properties that would help.

@Meestor_X not to keep you testing but I have been using Chilkats plugins for network connectivity (oAuth2, etc). I wonder if their tcp sockets are faster?

https://www.example-code.com/xojo/socket_connect.asp

Weird, I saw that exact same presence in a desktop proyect a couple years ago, make me think it was available on desktop.

Anyway, have you tried the chilkat plugin? Looks like it has more options than the MBS one

https://www.chilkatsoft.com/refdoc/xojoSocketRef.html

1 Like
Declare Function setsockopt Lib "Ws2_32.dll" Alias "setsockopt" ( _
s As Integer, _
level As Int32, _
optname As Int32, _
ByRef optval As Boolean, _
optlen As Int32 _
) As Int32

Const IPPROTO_TCP = 6
Const TCP_NODELAY = &h0001

Dim noDelay As Boolean = True
Dim noDelayLength As Int32 = 1 'byte length of noDelay

Dim ok As Int32 = setsockopt(YourSocketGoesHere.Handle, IPPROTO_TCP, TCP_NODELAY, noDelay, noDelayLength)
3 Likes

You listen on a port. Then you get later a DataAvailable event. There you can accept the request, which gives a new socket. In this mode you basically run it as ServerSocket.

@mikecotrone - Do you think that would speed up the Xojo TCPSockets?
How about on MacOS?

Yeah, Norm and I figured it out, thanks.

So, the RawSocketMBS is only 3x slower than .NET, and I can’t see any parameters that would speed that up further.
I would expect that using Threads would not increase the speed any (just reading one socket’s data and sending it to the other with no processing)…

I haven’t tried them. Paid for MBS so it would be great if I don’t have to buy another package. But, if those ones are free to try, I can experiment…

Overall the answer by disabling Nagle’s algorithm should only yield back some hundredths of a millisecond and it really only affects larger packet sizes (usually larger fragmented payloads). Granted since the 90s all Cisco engineers have disabled “No Service Nagle” until it was default in newer Cisco OSs.

Overall try it but I will be surprised if you notice anything.

Good luck!

Couple of ideas:

  1. What happens if you use memory blocks rather than strings for ConsoleMsg & EditorMsg?

  2. Rather than just blindly writing the variables, have you tried checking that their length > 0 via LenB before writing?

Thank you for your suggestions!

No difference.

I don’t think DataAvailable() will fire if there’s nothing to read. (I did a test both synchronously and asynchronously)

re> Testing the length first. I was looking at your tight loop code example at the time when I was thinking of this.

Have you tried working out if the delay is in the input or output? Maybe something like Wireshark might help.

No. Not sure how that would lead to a solution?

Is the problem:

  1. The data is being received on the socket and the Xojo framework is slow to pass it on.
  2. The Xojo framework is not sending the data immediately (causing an ever increasing delay).

Identifying where the problem is might allow you / others to come up with solutions.

also. What Xojo version are you using, what OS is this running on + do you know the number of CPUs / cores the computer has?

Fair enough, except there’s not likely anything that can be done with the built-in TCPSocket.

2019r1.1
MBP 2.3ghz 8-core i9 (MacOS)
and
Lenovo W520 2.5ghz i7 4-8core (don’t remember) (Win7 & Win10)

Same results on both.

Andy I am more intrigued. Can you share me this test project so I can beat on it tomorrow?

I actively use Xojo 2019r3,2 and 2020r2.

Thx

Thank you, Mike.
@npalardy and I looked at it and the Xojo TCPSocket is definitely very slow in comparison to the .NET socket.
Since it requires specialized hardware that I have in my house to test, I’m not sure what good the code would do since you can’t test it.
However, I’d be happy to zoom with you to show you the issue if you’re curious.