WebSocket Server

Share your advanced PureBasic knowledge/code with the community.
HanPBF
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Feb 19, 2010 3:42 am

Re: WebSocket Server

Post by HanPBF »

If I only asked earlier...
Now it works seemless!

I got strange client side disconnects in the browser; and information there is somewhat... less.

Thanks a lot for the new code and Your help!!!
HanPBF
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Feb 19, 2010 3:42 am

Re: WebSocket Server

Post by HanPBF »

How do I get the data sent from the client?

The public structure Event_Frame is used then?

Maybe too easy...


I am at that point; of course not only text but data...

Code: Select all

 Event_Frame\Payload = *Object\Client()\RX_Frame()\Data + *Object\Client()\RX_Frame()\Payload_Pos
          Event_Frame\Payload_Size = *Object\Client()\RX_Frame()\Payload_Size
          
          *Callback(*Object, *Object\Client(), #Event_Frame, Event_Frame)
          
          FreeMemory(*Object\Client()\RX_Frame()\Data)

Oh man, it's PeekS(..., -1, #PB_Ascii)...

The browser dares to send ascii that...

O.k. works now; thanks!
HanPBF
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Feb 19, 2010 3:42 am

Re: WebSocket Server

Post by HanPBF »

Hello,

just a little "problem".

In WebSocket_Server.pbi at this point:

Code: Select all

debug peeks(*Object\Client()\RX_Frame()\Data, -1, #PB_Ascii)
in

Code: Select all

Procedure Event_Callback(*Object.Object, *Callback.Event_Callback)
I get this result:

Code: Select all

‰C²+§Test send²+§
After all threads done I am in my callback and do this:

Code: Select all

*WSE\Text = PeekS(*Event_Frame\Payload, -1, #PB_Ascii)
I get this result:

Code: Select all

Test send²+§
Do the 3 characters at the end still belong to the protocol and can I strip them off simply?

Damn... got the problem writing this...
Payload size has to be used in peeks...

Will keep it in the forum...
Thorium
Addict
Addict
Posts: 1271
Joined: Sat Aug 15, 2009 6:59 pm

Re: WebSocket Server

Post by Thorium »

Dadido3 wrote:
Thorium wrote:Will you add TSL?
It's planned, but i can't say when i'll add it.

Edit:
If TLS is needed you can use a webserver as proxy. For NGINX this may be helpful: http://stackoverflow.com/questions/1210 ... le-ssl-wss. But i haven't tried it.
Since TLS is very important for my webservice i am using libwebsockets now. Finaly got it to compile. Compiling OpenSSL was a pain. Currently i am translating the example server from c to PB.
morosh
Enthusiast
Enthusiast
Posts: 293
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: WebSocket Server

Post by morosh »

hello:
project doesn't compile with PB5.60: error: Base64Encoder(): Incorrect number of parameters.

any trick?
thanks
PureBasic: Surprisingly simple, diabolically powerful
User avatar
Dadido3
User
User
Posts: 52
Joined: Sat Jan 12, 2008 11:50 pm
Location: Hessen, Germany
Contact:

Re: WebSocket Server

Post by Dadido3 »

Hi morosh,

replace Base64Encoder with Base64EncoderBuffer. Or just redownload, as i have updated the include.
morosh
Enthusiast
Enthusiast
Posts: 293
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: WebSocket Server

Post by morosh »

Thank you
PureBasic: Surprisingly simple, diabolically powerful
HanPBF
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Feb 19, 2010 3:42 am

[SOLVED] WebSocket Server

Post by HanPBF »

WebSocket does not work; using AJAX instead...



I use the example given with the WebSocket_Server code.

In Internet Explorer 11 I got this problem:
"SCRIPT12008: WebSocket Error Status Code 403, Not Found"
(When I put nonsense URL I get correct error "... Code 200 ...".)

In the PureBasic code the events are triggered!


Any idea?
I know that's no problem with PureBasic / WebSocket Server.

Put I could not find any solution.

Btw., Firefox works!

Any help really apreciated!
HanPBF
Enthusiast
Enthusiast
Posts: 562
Joined: Fri Feb 19, 2010 3:42 am

Re: WebSocket Server

Post by HanPBF »

"WebSocket does not work; using AJAX instead..."

To make things clear; the websocket server source post works of course!

My local config of internet explorer 11 is crazy and can not be changed.

Seems like it does not work with local web socket server while Firefox, Vivaldi works and IE11 works with echo websocket site.
dige
Addict
Addict
Posts: 1247
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Re: WebSocket Server

Post by dige »

@Dadido3: thanks! Works fine with PB 5.45 :D

If someone is interested in webapps, I built a chat client for the server with SpiderBasic for testing purposes:
http://forums.spiderbasic.com/viewtopic.php?f=12&t=1362
"Daddy, I'll run faster, then it is not so far..."
stmdbe2019
User
User
Posts: 89
Joined: Mon Aug 31, 2009 2:11 pm

Re: WebSocket Server

Post by stmdbe2019 »

1. My site is only HTTPS://www.example.com/chat.html
2. PB is running as ws://

How do you enable `WSS://` on the existing PB server?
(without hacking nginx, stunnel, proxy server's, not depending on third party tools absolutely natively with PB)
-----
Registered PureBasic Coder.
Thorium
Addict
Addict
Posts: 1271
Joined: Sat Aug 15, 2009 6:59 pm

Re: WebSocket Server

Post by Thorium »

shamun wrote:1. My site is only HTTPS://www.example.com/chat.html
2. PB is running as ws://

How do you enable `WSS://` on the existing PB server?
(without hacking nginx, stunnel, proxy server's, not depending on third party tools absolutely natively with PB)
You can't enable it. WSS uses TLS which the server posted here is not supporting and doing it without any third party tools/libs is a pretty big project.
I ended up using libwebsocket but you need to work your way through compiling openssl first, it was a pain. Compiling of libwebsocket was easy.
stevie1401
User
User
Posts: 42
Joined: Sat Oct 18, 2014 7:14 am

Re: WebSocket Server

Post by stevie1401 »

The server hangs up after a short time.
How can I do it without thread?
User avatar
Dadido3
User
User
Posts: 52
Joined: Sat Jan 12, 2008 11:50 pm
Location: Hessen, Germany
Contact:

Re: WebSocket Server

Post by Dadido3 »

I have tried to reproduce that bug, but i wasn't able to do so on Windows or Linux, even with over 100 clients. But while looking over the code i found a possible deadlock case which i fixed. (Double locking of a mutex from the same context)
There were also some other small things which i fixed and optimized, so it shouldn't hurt to update.

I also added a description and an example on how to use polling instead of the threaded callback. In case of polling, the include still uses threading internally, but the event callback will be called from whatever context you wish.
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 543
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: WebSocket Server

Post by bbanelli »

Dadido3 wrote:I have tried to reproduce that bug, but i wasn't able to do so on Windows or Linux, even with over 100 clients.
Hi Dadido3,

could you please clarify what is the particular constraint for number of concurrent users? Protocol itself, programming or hardware limitation?
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
Post Reply