Websocket Client

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Websocket Client

Post by infratec »

Updated the listing above.

Fixed 2 more bugs and added timeouts.
stevie1401
User
User
Posts: 81
Joined: Sat Oct 18, 2014 7:14 am

Re: Websocket Client

Post by stevie1401 »

Thank you for your efforts!
The web server is fine, try ws://doko-cafe.de:8090
At least now under Linux, there are no more errors and even the handshake is OK, but I still can't receive any data.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Websocket Client

Post by infratec »

You asked for wss and this is not working with doko-cafe.de, doesn't matter which client.

ws://doko-cafe.de:8090

works, I get:
< {"Username":[""],"Type":"Userlist"}
But nothing else.
What can we send to this server to get a valid reply?

"HelloWorldServer." ???
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Websocket Client

Post by infratec »

Made other bugfixes and restructuring. (pbf file no longer needed)

https://www.purebasic.fr/english/viewto ... 82#p639382
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Websocket Client

Post by infratec »

Added CloseConnection() and modified pong to answer also masked pings :wink:
stevie1401
User
User
Posts: 81
Joined: Sat Oct 18, 2014 7:14 am

Re: Websocket Client

Post by stevie1401 »

Great!!!
It was my mistake with doko-cafe.de.
I had configured nginx for the wrong site :D
You can test it now at wss://doko-cafe.de/test
It works perfectly, thank you so much!!
stevie1401
User
User
Posts: 81
Joined: Sat Oct 18, 2014 7:14 am

Re: Websocket Client

Post by stevie1401 »

For longer strings (over 700 characters), the string is no longer transmitted properly.
There is a strange character at the beginning of the string, and the last character of the string is missing.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Websocket Client

Post by infratec »

Fixed.
A nother bug in the original code: the pos variable was wrong if the length was in 2 extra bytes.

Ups ... forgot some test code.
stevie1401
User
User
Posts: 81
Joined: Sat Oct 18, 2014 7:14 am

Re: Websocket Client

Post by stevie1401 »

I'm really sorry, but it still doesn't work.
Sometimes it works, but after a few tries, it doesn't work again.

Here, even after several attempts, an error occurs:

Code: Select all

  *WebsocketClient\ReceiveBuffer = AllocateMemory(*WebsocketClient\frame_size, #PB_Memory_NoClear)
"[ERROR] AllocateMemory(): Cannot allocate a memory area with size 0."

Either this error occurs or it shows the strange character again and the string is incomplete.

Maybe an admin can move this topic to Coding Questions, where more people will definitely look at it.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Websocket Client

Post by infratec »

One question: why do you not look after it?

If you are able to find the location, you can do something against it.
Why should someone which don't need this should do all the work?

And I can not test it, since I don't knaow what you are exactly doing to make it fail.

With the demo code and your wss://doko-cafe.de/test and sending 804 bytes it does not fail.
Do you use the demo code for your tests?

Use ShowMemoryViewer to show the content at the location where it fails.
Since there is a valid frame_type, the Payloadsize should not be 0.

Or your server sents fragmented frames which, as you can read, are not yet implemented.

Have you tested your server with a javascript client?
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Websocket Client

Post by infratec »

I again checked and improved the code, but I was not able to find a bug.
Even with your /test page I was not able to reproduce a fault.

I added the ping option and removed redundancies.
stevie1401
User
User
Posts: 81
Joined: Sat Oct 18, 2014 7:14 am

Re: Websocket Client

Post by stevie1401 »

Thank you for your support.
I tested with your WebSocket client and the server wss://echo.websocket.org.
Since I'm not a computer scientist, just a hobbyist, I'm completely overwhelmed when it comes to creating or testing WebSocket code.
But of course, I don't expect you to program it for me.
It would be nice if Fred would implement WebSockets so that Basic programmers could also use them.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Websocket Client

Post by infratec »

I pressed now rapidly Send with 85 bytes for a minute (more then 100 sendings)
and then with 189 bytes for a minute.

I was not able to crash something,

PB 6.21b5 x86 asm backend on windows 10 x64 latest version.

But even if something is inbuild, it is not 100% error free :wink:
And then you can nothing adjust or correct.

But WebViewGadget is inbuild, so you can use javascript to do that stuff.
Create a hidden WebviewGadget, program your client in javascript and communicate with your main program.
infratec
Always Here
Always Here
Posts: 7577
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Websocket Client

Post by infratec »

Now you also have the possibility to use the libcurl websocket implementation.
https://curl.se/libcurl/c/libcurl-ws.html

I added the websocket stuff to libcurl.pbi and also an example.
https://www.purebasic.fr/english/viewto ... 92#p639592
Post Reply