Click here to Skip to main content
15,896,528 members
Articles / Web Development / HTML

A C++ Websocket server for realtime interaction with Web clients

Rate me:
Please Sign up or sign in to vote.
4.81/5 (23 votes)
17 May 2012Apache5 min read 179.5K   22.3K   105  
A Websocket protocol implementation atop the ush Framework real time library plus a demo example featuring four types of communication workflows between the HTML5 web client and the server.

#include "../include/Plateform.h"


#ifdef Plateform_Windows
typedef DWORD ThreadIDType;
typedef HANDLE ThreadHandleType;
#define AtomicIncrement(i) ::InterlockedIncrement ( (long*)&i )
#define AtomicDecrement(i) ::InterlockedDecrement ( (long*)&i )
#define AtomicExchange(i, val) InterlockedExchange((long*)&i, val )
#else

#ifdef Plateform_Linux
typedef pthread_t ThreadIDType;
typedef pthread_t ThreadHandleType;
#define AtomicIncrement(i) __sync_add_and_fetch(&i, 1)
#define AtomicDecrement(i) __sync_add_and_fetch(&i, -1)
#define AtomicExchange(i, val) __sync_lock_test_and_set (&i, val)
#endif

#endif


#ifdef Plateform_Linux
#ifndef SOCKET
typedef int SOCKET;
#endif

#ifndef SOCKADDR_IN
typedef sockaddr_in SOCKADDR_IN;
#endif

#ifndef IN_ADDR
typedef in_addr IN_ADDR;
#endif

#ifndef UINT
typedef unsigned int UINT;
#endif

#define Sleep usleep
#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Technical Lead
Tunisia Tunisia
Services:
http://www.pushframework.com/?page_id=890

Comments and Discussions