Home > Uncategorized > C++ WebSocket server – Source-Code released

C++ WebSocket server – Source-Code released

Hey folks,

I open sourced my C++ WebSocket Server implementation. It is a pretty basic C++11 server running on POSIX/MacOSX systems. It supports the most recent WebSocket implementation and works fine with Chrome/Safari and Firefox. Windows is not supported on purpose.

It was an awesome learning process to write it and I learned so much about HTML etc, that I can suggest for anyone who is interested in low level network programming to do the same.

The server supports MYSQL, JSON and runs on multiple threads. So quite cool 🙂

The read loop is not yet finished tho.. If you for example stream a big video file, the current thread will be blocked until it is received. That is a no-go and i am working on fixing it!

The runloop is based on select (shame on me i know) and uses the same principle NodeJS uses for example. One steady loop with event callbacks.

Check it out:

https://github.com/MarkusPfundstein/C—Websocket-Server

  1. November 20, 2012 at 11:52 pm

    My coder is trying to convince me to move to .net from PHP.
    I have always disliked the idea because of the costs.
    But he’s tryiong none the less. I’ve been
    using Movable-type on a variety of websites for about a year and am concerned about switching to
    another platform. I have heard excellent things about blogengine.
    net. Is there a way I can transfer all my wordpress
    content into it? Any kind of help would be greatly appreciated!

    • December 11, 2012 at 8:43 am

      You ask the wrong guy here as I am very heavy biased AGAINST everything related to Microsoft. 🙂 Move to NodeJS if you want to get away from php.

  2. Flavio
    December 11, 2012 at 8:29 am

    This looks nice, that may be exactly what I need to tryout some stuff but…noob question: how do I use it? How do I compile it? :/

    • December 11, 2012 at 8:42 am

      Hi,

      in the build folder is makefile. Just cd in it and do ‘make all’.

      You will need the following libraries to be able to compile it:

      libmysqlclient
      libssl
      libjson
      libcrypto

      And i am using c++11 features so gcc 4.7 or higher 😉

      • Flavio
        December 11, 2012 at 9:56 am

        Hey, thanks for the really quick answer, but when I try to make it I get:
        “make: *** No rule to make target `all’. Stop.” , is it possible to go through every folder and make every single target?
        And, besides, do I get an executable? main.o looks more like a library…

        Sorry but I’m really a noob :/

  3. December 11, 2012 at 10:00 am

    Sorry . it is ‘make debug’

    🙂

    The exec file will be called ut.out

    the .o files are object files generated from the cpp and h files which get than linked together with all necessary libraries to ut.out

  4. December 11, 2012 at 10:00 am

    Flavio :

    Hey, thanks for the really quick answer, but when I try to make it I get:
    “make: *** No rule to make target `all’. Stop.” , is it possible to go through every folder and make every single target?
    And, besides, do I get an executable? main.o looks more like a library…

    Sorry but I’m really a noob :/

    Sorry . it is ‘make debug’

    The exec file will be called ut.out
    the .o files are object files generated from the cpp and h files which get than linked together with all necessary libraries to ut.out

  5. Flavio
    December 11, 2012 at 10:11 am

    Markus Pfundstein :

    Flavio :
    Hey, thanks for the really quick answer, but when I try to make it I get:
    “make: *** No rule to make target `all’. Stop.” , is it possible to go through every folder and make every single target?
    And, besides, do I get an executable? main.o looks more like a library…
    Sorry but I’m really a noob :/

    Sorry . it is ‘make debug’
    The exec file will be called ut.out
    the .o files are object files generated from the cpp and h files which get than linked together with all necessary libraries to ut.out

    Yei 🙂 i renamed it and now with make all it starts to compile 🙂 I just got a problem with the following expression in engine.cc (82-86)
    “int port = ; // get from init_file
    std::string username = ;
    std::string password = ;
    std::string database = ;
    std::string host = ;”

    The compiler is not happy telling me I need a “primary expression” before < and ; , I suppose it means those are not string and is not an integer…any clue?
    Sorry for bothering 😦

    • December 11, 2012 at 10:19 am

      port is an int which should be the port you want to let your server listen too.

      i wanted to implement a ini file but havent had the time yet.

      the rest you give login data to your sql database 🙂

  6. Flavio
    December 11, 2012 at 10:27 am

    Markus Pfundstein :
    port is an int which should be the port you want to let your server listen too.
    i wanted to implement a ini file but havent had the time yet.
    the rest you give login data to your sql database

    Thanks a lot 🙂 got it!! 🙂

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: