Can you post a link to a tutorial you found?
In C/C++, this is fairly complicated (if you are just starting out).
I saw this same type of question on different forums and I saw:
you might want to use the event loop support provided by GLib and use the related networking library GNet .
Here's how to use GNet to open a socket on port 4000, then close every connection made to it. There is a little bit of magic here as the server registers itself with the default main context as part of its creation.
I modified the second link as theirs was broken.
#include <glib.h>
#include <gnet.h>
void client_connect(GServer G_GNUC_UNUSED *server, GConn *conn, gpointer G_GNUC_UNUSED user_data){
g_print("Connection from %s\n", conn->hostname);
gnet_conn_disconnect(conn);
gnet_conn_unref(conn); conn = NULL;
}
int main(void){
GMainLoop *loop = g_main_loop_new(NULL, FALSE);
GServer *server;
gnet_init();
server = gnet_server_new(NULL, 4000, client_connect, NULL);
g_main_loop_run(loop);
g_main_loop_unref(loop); loop = NULL;
return 0;
} thines01
Postaholic
Team Colleague
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402