shortcut constants and handling big tcp data

Just starting out? Need help? Post your questions and find answers here.
nsstudios
Enthusiast
Enthusiast
Posts: 275
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

shortcut constants and handling big tcp data

Post by nsstudios »

Hi all,

I was wondering if there was a way to use more keys than available with #pb_shortcut_x constants with AddKeyboardShortcut cross-platform?
I noticed that ShortcutGadget returns vk constants on Windows, so could I use the same constants cross-platform, or would I have to use separate values for every OS?
I was specifically looking for keys like period, slash, comma, apostrophe, semicolon, backslash, etc.

I'm also wondering what's the proper way to handle sending/receiving strings that are bigger than the maximum length over tcp?
The code I have right now uses a simple send network string for sending, and the following for receiving:

Code: Select all

#bufsize=65536
Protected *in=AllocateMemory(#bufsize), in$, c=ClientEvent()
Protected r=ReceiveNetworkData(c, *in, #bufsize)
Select r
Case -1
Break
Case 0
Delay(1000)
Default in$+PeekS(*in, r, #PB_UTF8|#PB_ByteLength)
EndSelect
ForEver
but as long as I'm not doing it from local network, the string gets split in multiple parts, usually about 3000 characters each.
The receiving code is threaded, but I get the same result even when it's not.
I'd appreciate any suggestions for fixing this.

Thanks.
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: shortcut constants and handling big tcp data

Post by mk-soft »

1. The shortcuts are also different for the OS. So always use the PB constants

2. In case of network always check the reception if the data has arrived completely.

- Work with control characters (e.g. #STX, #ETX)
! Remember that without synchronization after #ETX (EndOfText) already a #STX (StartOfText) can be read from the receive buffer.

- Work with headers. Link: Module NetworkTCP
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
nsstudios
Enthusiast
Enthusiast
Posts: 275
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

Re: shortcut constants and handling big tcp data

Post by nsstudios »

OK, but what do I do if I need keys that #pb_shortcut constants don't offer?
I already have a delimiter that I split data with, and I tried to make it read until it is the last character in the string, but it didn't work.
Thanks for the module recommendation, will take a look. :)
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: shortcut constants and handling big tcp data

Post by infratec »

A 'normal' network packet contains at maximum 1500 bytes (until you can use jumboframes)
So if you look with WireShark you will see many more packets as you think.

Everything larger is handled internally by OS.

If you want OS independency, you have to handle your big data by yourself and split them into 1400 byte packets
(for example)

You can test this (windows) with

Code: Select all

ping -f -l 1432 purebasic.fr
-f means: don't fragment (use one packet)
-l is the data size which is used.

1432 is my maximum data size which is usable over my router.
If I increase it, it will not work.

If you have 2 questions, than use 2 topics.
Else it will result in a mess, since not everyone answers at both questions.
Last edited by infratec on Sun May 24, 2020 7:34 pm, edited 1 time in total.
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: shortcut constants and handling big tcp data

Post by mk-soft »

Help me...

You don't use keyboard shortcuts to separate data. Instead you take control characters from the ASCII table smaller than the character "Space" (char<32)
See wiki ...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
nsstudios
Enthusiast
Enthusiast
Posts: 275
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

Re: shortcut constants and handling big tcp data

Post by nsstudios »

@Infratec Thanks for the info, and good idea, because it did create confusion about shortcuts.
@mk-soft I was just wondering how to go about registering keys that aren't offered by #pb_shortcut constants with AddKeyboardShortcut, it's a totally separate problem from the network one.
Sorry for the confusion.
Post Reply