ServerSocket / Socket Write limit

For questions about Gambas web tools.
Post Reply
User avatar
BruceSteers
Posts: 1874
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

ServerSocket / Socket Write limit

Post by BruceSteers »

Is it common for HTTP sockets to have a limited Write length for data or can it be set/raised?

I have this program feature.....

I have a ServerSocket running and i connect my program to it. other programs can also connect to it and those connected can share data.

So for example one program will request the scores list from another user.

When requesting client-1 sends a request msg to the webserver that then sends the request to the user (client 2), then their program sends the requested data back to the server to then be sent to client 1.

The problem is this...
When using my local apache server it all works as expected and the data (quite a long string) is sent in one shot.

But, when i upload the webserver to my online server and try to use it from there I am finding my Read event is only getting some of the data, it's truncated and the rest comes through in another Read event !?

Anyone know if there Is there a way to stop that happening?

I tried Socket.Begin, Socket.Send but that didn't help.
If at first you don't succeed , try doing something differently.
BruceS
vuott
Posts: 304
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: ServerSocket / Socket Write limit

Post by vuott »

Hello.
How is the “Read ...” command line ?
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
BruceSteers
Posts: 1874
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: ServerSocket / Socket Write limit

Post by BruceSteers »

vuott wrote: Monday 22nd July 2024 12:10pm Hello.
How is the “Read ...” command line ?
It was simply this...

  sTxt = Read #Soc, Lof(Soc)


I have been able to handle it as i know the text should end with a "}" as it's a collection setting string
If it does not end in } then it saves the currently read text to a buffer and appends each next read event to the buffer until it does end with }

like this...

  Dim sTxt As String
  Dim Soc As Socket = Last

  sTxt = Read #Soc, Lof(Soc)
  sTxt = RTrim(FromUrl(sTxt))
  If Not sTxt Then Return

  If $sBuff Then  ' if text is in the buffer then append the read text to it.
    sTxt = $sBuff & sTxt
    $sBuff = ""
  Endif

    If sTxt Not Ends "}" Then  ' if text does not end in } it is incomplete so save to buffer and wait for next read.
      $sBuff = sTxt
      Return
    Endif

'  At this point sTxt should now be a complete text and not cause the next line to error.
Dim cCol As Collection = Settings.FromString(sTxt)



Would have been much easier if the Read event got all the text in one shot like it does on my local apache server.
I wondered if there's an apache setting I could use on the web server? or a header that forces read/write events to not get split.
If at first you don't succeed , try doing something differently.
BruceS
vuott
Posts: 304
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: ServerSocket / Socket Write limit

Post by vuott »

BruceSteers wrote: Monday 22nd July 2024 1:57pm It was simply this...

  sTxt = Read #Soc, Lof(Soc)
Is this :? idea able to help you, BruceSteers ?
Private ht As New HttpClient As "HttpClient1"
Private $st As String


Public Sub .... etc...etc...

  ....etc...etc....

End


Public Sub HttpClient1_Read()  

  Dim sBuf As String  

  If Lof(ht) Then   
    sBuf = Read #ht, Lof(ht)
    $st &= sBuf
  End If

End


Public Sub .... etc...etc...

  ...etc....
 ...etc....
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
thatbruce
Posts: 237
Joined: Saturday 4th September 2021 11:29pm

Re: ServerSocket / Socket Write limit

Post by thatbruce »

Are you using JSON? In any way. Then beware of stuff (sorry, I have stuff that looks simillar)
User avatar
BruceSteers
Posts: 1874
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: ServerSocket / Socket Write limit

Post by BruceSteers »

thatbruce wrote: Wednesday 24th July 2024 4:52pm Are you using JSON? In any way. Then beware of stuff (sorry, I have stuff that looks simillar)
no just gb.net ServerSocket.class on the web server and Socket.class on the clients.

Trying normal Socket (steam) Read / Write methods.
sending plain ascii text (basically a gb.settings style file text)

I'm guessing the data being sent in multiple Writes is a server limitation, or a setting i do not know how to adjust.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
gbWilly
Posts: 111
Joined: Friday 23rd September 2016 11:41am
Location: Netherlands
Contact:

Re: ServerSocket / Socket Write limit

Post by gbWilly »

I use daemons on my server (at work and at home) that run serversocket based daemons as services.
I use them for remote managing the servers. Think remote update, check log files, restart services and the whole lot.
It is all intranet based

I have a few questions about your setup:

It seems it works in the 'intranet' setup or did you test on your localhost (so your own machine -> detail matters)?
What is the length of what you are sending?
What is the code you use for sending?
What port are you sending/receiving?
What server socket properties have you set/not set?

Just a few questions that pop up that might be of influence in understanding and solving the matter.

I've had same daemon producing different results on different servers running exact same os and configuration.
The difference being that one server threw an error that couldn't bind to the port and the other didn't. Both are running daemon v1.0 (giving error on 1 server) and the recently improved daemon v2.0 (on a different port)
Both servers and daemons did accept my connection... :shock:
Still don't know what is causing the error, but it all works on both servers at work. Daemon v 2.0 is running solo at home server.

I do know that detail really matters.

Some suggestions that might change your result/help solve the problem/give you more insight in the matter:
- Wait in code for less than a seconds can help, if you send a lot in sequence.
- Slower systems react different that faster systems, test for this and see how you can tweak, sometimes simplt changing order stuff happens
- A network sniffer having a look at what really goes on on the cable will help (specially since you send ascii you can see every package contentr in details) will give you insight in the matter.

Keep me posted on your findings, happy to think along..
gbWilly
- Dutch translation for Gambas3
- Gambas wiki content contributer
- Gambas3 Debian repository


... there is always a Catch if things go wrong!
User avatar
gbWilly
Posts: 111
Joined: Friday 23rd September 2016 11:41am
Location: Netherlands
Contact:

Re: ServerSocket / Socket Write limit

Post by gbWilly »

Ever solved this?
gbWilly
- Dutch translation for Gambas3
- Gambas wiki content contributer
- Gambas3 Debian repository


... there is always a Catch if things go wrong!
User avatar
BruceSteers
Posts: 1874
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: ServerSocket / Socket Write limit

Post by BruceSteers »

No , only in the way previously mentioned.
I make sure the text being sent has a known end sequence.

It was a case of the local machine (localhost) working fine and sending all the text all in one shot but the online server sending it in multiple parts.

So the answer was repeatedly reading the input and adding the text to a string until it detects the end sequence.

Sorry i did not reply to your last message. it got by me. so to answer..
I have a few questions about your setup:

It seems it works in the 'intranet' setup or did you test on your localhost (so your own machine -> detail matters)?
localhost , just apache2

Code: Select all

What is the length of what you are sending?
It varies , basically Images converted to Base64 text.

Code: Select all

What is the code you use for sending?
Write #hSocket, sData, , String.Len(sData)

Code: Select all

What port are you sending/receiving?
8083
What server socket properties have you set/not set?
$hServer = New ServerSocket As "Sock"
$hServer.Port = 8083
$hServer.Type = Net.Internet
$hServer.Listen
If at first you don't succeed , try doing something differently.
BruceS
User avatar
gbWilly
Posts: 111
Joined: Friday 23rd September 2016 11:41am
Location: Netherlands
Contact:

Re: ServerSocket / Socket Write limit

Post by gbWilly »

I was just curious if you ever got closer to the cause.

I experience different behavior on different systems, all running same RemoteDaemon application using Socket server and client for 2-way communication with my manager software on my system.
It all works now, but over time needed some experimenting now and then on sending and receiving end with short wait instructions.

I also needed to start using end markers (actualy start markers) in the send info if a lot of data in sequence got send to my system. or vice versa. Sometimes seemed that the receiving end couldn' t handle the load in some situations. Start markers was part of the solution on the sending side with short waits in between 0.01 if different stuff in fast sequence is being send. I didn't have to do much on the receiving side other than have it recognize the start markers and act accordingly.

Your problems seems a likewise case, but like mine it seems you got it doing what you want it to do.
gbWilly
- Dutch translation for Gambas3
- Gambas wiki content contributer
- Gambas3 Debian repository


... there is always a Catch if things go wrong!
Post Reply