Theldus / wsServer

wsServer - a tiny WebSocket server library written in C
https://theldus.github.io/wsServer
GNU General Public License v3.0
422 stars 80 forks source link

Only connect and send ? [client only] #35

Closed hannesa2 closed 2 years ago

hannesa2 commented 2 years ago

There are great examples how to run a server with ease, but unfortunately I'm a bloody C beginner.

How to make a C program with your lib, which only connect to server and send some text ?

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ws.h>

int main(void)
{
     while (1) {
     ws_sendframe_txt(fd, "hello", false); // but from where get this 'fd' ?
         delay(100);
    }
}

But how to connect to server and from where I get this fd ?

hannesa2 commented 2 years ago

I mean something like this https://github.com/Theldus/wsServer/blob/master/example/send_receive.html#L38-L65 but only in C

Theldus commented 2 years ago

Hi @hannesa2, wsServer, as you can infer from the name, is a websocket server, not a client, so you cannot connect to a server and send messages through this library.

What you can do with this library is run a server in C, and communicate with clients through it. If you want the opposite, this library unfortunately doesn't suits your needs.

Websockets are often used by browsers, etc., as a top-level layer over TCP, which allows you to send and receive data without the use of polling. If you just want to create a server and a client (both in C) without the participation of browsers, you can stick to the normal use of sockets, as this tutorial explains.