Page 1 of 1

Socket splitting data

Posted: Tue Dec 13, 2022 10:10 pm
by mikelpapamike
Hello everyone,

I'm currently trying to build an App that connects to a 3rd party software which provides some data in json format. Then I translate the json data to xml and send them via socket to a socket server I built based on the chat server/client sample stack in order to broadcast the XML array to multiple clients that are connected to chat server. But the server broadcasts the whole xml data in 2 messages instead of one, this way I don't know when all the data have been received on the client in order to start manipulating them and clear buffer to wait for the next message(updated xml data).

When I receive the data in json format I run a .bat file that translates them to xml and stores it in a file in order to read them elsewhere.

The reason I can't share the folder of the file with the clients is that some of them may be over internet, so on the chat server I can port forward and have all clients connect to it and receive the messages, plus I want the lower possible delay.

Any idea why my socket message is being split? Is there a size limit that can be increased ?

Thanks in advance.

Re: Socket splitting data

Posted: Wed Dec 14, 2022 2:25 pm
by mikelpapamike
The only way I managed to know when ive sent all the data, is to add a special character like "^" and wait until "^" at the client side, but I dont know what will happen if the data will contain somewere this character. :?:

Re: Socket splitting data

Posted: Fri Jan 27, 2023 7:03 pm
by mikelpapamike
Thats the issue that I need to use a character that I will be 1000% sure that will never be used!

Re: Socket splitting data

Posted: Sat Jan 28, 2023 7:40 pm
by jacque
I like numToChar(8) which is the delete key. It isn't typeable and will never appear in any text. NumToChar is deprecated but still works, but if you want to be technically correct you can use numToCodepoint instead to do the same thing. NumToChar(3) is another option which also can't be typed.

Re: Socket splitting data

Posted: Mon Jan 30, 2023 12:57 am
by mwieder
I tend to use NumToByte(3) and NumToByte(4) quite a lot for transmission control chars.

Packet size is determined by the operating system's MTU setting (nominally 1500 bytes) but note that it may be negotiated across intervening routers. But if you're communicating with a remote server then it's in control of the packet size it sends to you.

Re: Socket splitting data

Posted: Mon Jan 30, 2023 4:42 am
by SparkOut
I have often wondered why people don't ever seem to use ASCII 28 to 31, which comprises a group of codes originally designated as separators (record, unit, etc).
Is there a reason that these codes seem ostracised?

Re: Socket splitting data

Posted: Mon Jan 30, 2023 6:36 am
by mwieder
It's an extra character to type, and programmers are by nature lazy.

Re: Socket splitting data

Posted: Mon Jan 30, 2023 8:24 am
by SparkOut
How is it more to type than ASCII 3 or 4?

Re: Socket splitting data

Posted: Mon Jan 30, 2023 8:46 am
by mwieder
"NumToByte(3)" = 12 chars
"NumToByte(28)" = 13 chars
<g>

Re: Socket splitting data

Posted: Mon Jan 30, 2023 10:55 am
by SparkOut
:lol:
Oh well.

I am really curious whether there is a serious reason why (apparently) nobody in the world uses these delimiters though.

Re: Socket splitting data

Posted: Mon Jan 30, 2023 11:03 am
by Klaus
Call me "nobody" :-)

Re: Socket splitting data

Posted: Mon Jan 30, 2023 7:19 pm
by mwieder
It *is* a good question.
I got into the habit of using NumTtoByte(4) because it's defined as EOT.
But I haven't given much thought to the 28->31 chars.

Re: Socket splitting data

Posted: Mon Jan 30, 2023 7:40 pm
by jacque
I'm a nobody too, never thought about the 28-31 set.

Am I correct that we can use numToByte for any ascii code up to 256? When do I need numToCodepoint?