Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to write a simple server with tcllib's websocket

574 views
Skip to first unread message

kevin...@googlemail.com

unread,
Jun 20, 2014, 6:20:28 PM6/20/14
to
I need to write a very simple websocket server but cannot figure out how to
do this with ::websocket::server, websocket::live, a.s.o,
and didn't find any (server) example.
In fact, I don't know what kind of sock params I have to give to the procs...

Any help is welcome.

kevin...@googlemail.com

unread,
Jun 28, 2014, 7:26:25 AM6/28/14
to
I figured out how to do it, it might be useful to somebody.
Here is the (pseudo)code.

set srvSock [socket -server handleConnect $PORT]
# 1. declare the (tcp) server-socket as a websocket server
::websocket::server $srvSock

# 2. register callback
::websocket::live $srvSock /somepath wsLiveCB

# the usual tcl-tcp stuf (I don't (want to) use an http server package)
proc handleConnect {cs addr p} {
.............
fileevent $cs readable [list handleRead $cs]
.............
}

proc handleRead {cs} {
.............
# once having groked the HTTP GET headers
# 3. let's check valid
if {[::websocket::test $srvSock $cs /somepath $hdrs]} {
# 4. upgrade the socket
::websocket::upgrade $cs

# from now the wsLiveCB will be called (not anymore handleRead).

proc wsLiveCB {cs op par args} {
.......
switch $op {
request { ..... }
close { ..... }
disconnect { ..... }
text {
.....
}
}
......

MelHeravi

unread,
Feb 15, 2016, 4:06:37 PM2/15/16
to
Can you please send me the complete example code?
My guessing is not working :(

thank you


Rich

unread,
Feb 15, 2016, 4:55:40 PM2/15/16
to
MelHeravi <MelH...@gmail.com> wrote:
> Can you please send me the complete example code?

No


MelHeravi

unread,
Feb 15, 2016, 6:32:07 PM2/15/16
to
I just need the bare bone stuff like $hdrs ?? I have no idea where that comes from in your code

if {[::websocket::test $srvSock $cs /somepath $hdrs]}

Appreciate your time


--



Rich

unread,
Feb 15, 2016, 10:13:47 PM2/15/16
to
It is not "our" code.

In this instance, grep is your friend. Use grep.



Emmanuel Frecon

unread,
Feb 16, 2016, 3:41:28 PM2/16/16
to
I suggest that you take a look at the code at:

https://github.com/efrecon/til/blob/master/minihttpd/httpd.tcl

This should provide you with a medium-sized example.
0 new messages