[fpc-pascal] fcl-web websocket

Andrew Haines andrewd207 at aol.com
Mon Dec 26 06:00:49 CET 2022


On 12/25/22 6:06 PM, Michael Van Canneyt via fpc-pascal wrote:
>
> Does the sample chat client/program work for you ?
See below
>
> When I have a moment, I'll look at your test program.

Thank you

>
> Michael.
>
>

I'm not sure, maybe. It seems like the clients are not receiving 
messages. Also, using strace I realized the server ignores the port and 
uses 6060. I tried with and without threading.

./server/wsserver -p 8080 -t pool
Received message: { "from" : "client1", "msg" : "Hello, this is a 
friendly greeting message from the client", "to" : "client1" }
Received message: { "from" : "client2", "msg" : "Hello, this is a 
friendly greeting message from the client", "to" : "client2" }
Received message: { "from" : "client2", "msg" : "Hello to 1", "to" : 
"client1" }

Received message: { "from" : "client1", "msg" : "I didn't hear anything. 
Are you there?", "to" : "client2" }

Connection 1 disappeared
Connection 1 disappeared
Connection 2 disappeared
Connection 2 disappeared


./client/wsclient -u ws://localhost:6060/  -a client2
Enter message or command (/stop /help), empty message will just check 
for incoming messages
client2> Hello to 1
Recipient> client1
client2>

client2> /quit


./client/wsclient -u ws://localhost:6060/ -p -a client1
Enter message or command (/stop /help), empty message will just check 
for incoming messages
client1>
client1> I didn't hear anything. Are you there?
Recipient> client2
client1>
client1> /quit

State               Recv-Q Send-Q                             Local 
Address:Port                                Peer Address:Port Process
ESTAB               176 0 127.0.0.1:36486 127.0.0.1:6060 
users:(("wsclient",pid=1026336,fd=3))
ESTAB               204 0 127.0.0.1:36502 127.0.0.1:6060 
users:(("wsclient",pid=1026342,fd=3))

Andrew

PS Here is the strace from a client without sending messages, but 
pressing the 'enter' key once..

socket(AF_INET, SOCK_STREAM, IPPROTO_IP) = 3
getsockopt(3, SOL_SOCKET, SO_RCVTIMEO_OLD, 
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", [16]) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(6060), 
sin_addr=inet_addr("127.0.0.1")}, 16) = 0
sendto(3, "GET / HTTP/1.1\r\n", 16, MSG_NOSIGNAL, NULL, 0) = 16
sendto(3, "Host: localhost:6060\r\n", 22, MSG_NOSIGNAL, NULL, 0) = 22
sendto(3, "Upgrade: websocket\r\n", 20, MSG_NOSIGNAL, NULL, 0) = 20
sendto(3, "Connection: Upgrade\r\n", 21, MSG_NOSIGNAL, NULL, 0) = 21
sendto(3, "Origin: localhost\r\n", 19, MSG_NOSIGNAL, NULL, 0) = 19
sendto(3, "Sec-WebSocket-Key: 3pqrw1xgwqSel"..., 45, MSG_NOSIGNAL, NULL, 
0) = 45
sendto(3, "Sec-WebSocket-Version: 13\r\n", 27, MSG_NOSIGNAL, NULL, 0) = 27
sendto(3, "\r\n", 2, MSG_NOSIGNAL, NULL, 0) = 2
recvfrom(3, "H", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "T", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "T", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "P", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "/", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "1", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, ".", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "1", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, " ", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "1", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "0", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "1", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, " ", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "S", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "w", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "i", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "t", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "c", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "h", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "i", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "n", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "g", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, " ", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "P", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "r", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "o", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "t", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "o", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "c", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "o", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "l", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "s", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "\r", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "\n", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "U", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "p", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "g", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "r", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "a", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "d", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "e", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, ":", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, " ", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "w", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "e", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "b", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "s", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "o", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "c", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "k", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "e", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "t", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "\r", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "\n", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "C", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "o", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "n", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "n", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "e", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "c", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "t", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "i", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "o", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "n", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, ":", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, " ", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "U", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "p", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "g", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "r", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "a", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "d", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "e", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "\r", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "\n", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "S", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "e", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "c", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "-", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "W", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "e", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "b", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "S", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "o", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "c", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "k", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "e", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "t", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "-", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "V", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "e", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "r", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "s", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "i", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "o", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "n", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, ":", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, " ", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "1", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "3", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "\r", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "\n", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "S", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "e", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "c", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "-", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "W", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "e", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "b", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "S", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "o", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "c", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "k", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "e", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "t", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "-", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "A", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "c", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "c", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "e", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "p", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "t", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, ":", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, " ", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "Y", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "d", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "C", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "Y", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "e", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "Y", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "M", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "S", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "G", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "8", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "E", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "q", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "i", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "f", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "7", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "E", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "J", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "R", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "K", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "B", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "/", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "C", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "N", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "g", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "C", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "7", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "A", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "=", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "\r", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "\n", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "\r", 1, MSG_NOSIGNAL, NULL, NULL) = 1
recvfrom(3, "\n", 1, MSG_NOSIGNAL, NULL, NULL) = 1
write(1, "Enter message or command (/stop "..., 92Enter message or 
command (/stop /help), empty message will just check for incoming messages
) = 92
mmap(NULL, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 
0) = 0x7f86d8b81000
mmap(NULL, 32768, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 
0) = 0x7f86d8b79000
sendto(3, "\201n{ \"from\" : \"client2\", \"msg\" : "..., 112, 
MSG_NOSIGNAL, NULL, 0) = 112
select(4, [3], NULL, NULL, {tv_sec=0, tv_usec=0}) = 0 (Timeout)
write(1, "client2> ", 9client2> )                = 9
read(0, [--ENTER KEY--]

"\n", 256)                      = 1
select(4, [3], NULL, NULL, {tv_sec=0, tv_usec=0}) = 1 (in [3], left 
{tv_sec=0, tv_usec=0})
write(1, "client2> ", 9client2> )                = 9
read(0,







More information about the fpc-pascal mailing list