Code Snippet

warning: Creating default object from empty value in /home/hplus/ on line 33.
This article contains a little code.
jwatte's picture


//  chatserver.cpp
//  The Win32 GUI for the chat server sample.
//  This file runs the dialogs, and defers to the chathost.cpp 
//  file for networking and user management.
#include <winsock2.h>
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <string>
#include "etwork/etwork.h"
#include "etwork/timer.h"

jwatte's picture


//  chathost.h
//  This file defined a simple interface for a service that 
//  hosts text chat over a specific port.
//  Intended as a sample for how to use the message-layer 
//  functionality of the Etwork networking library.
//  <a href="</p>
<p>#if" title="</p>
<p>#if</p></a> !defined( chathost_h )
#define chathost_h
//  Information kept about each client.
struct ChatClient {

jwatte's picture


//  chathost.cpp
//  Illustrates how you can wrap Etwork into a layer 
//  that understands commands, such as "log in," "log out" 
//  and "pass on this text".
#include "etwork/etwork.h"
#include "etwork/timer.h"
#include "chathost.h"
#include <assert.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>

jwatte's picture


The sample chat server in the Etwork networking library.

jwatte's picture


// Microsoft Visual C++ generated include file.
// Used by chatclient.rc
#define IDD_CONNECT                     101
#define IDD_CHATCLIENT                  102
#define IDD_CHATUSER                    102
#define IDC_HOSTNAME                    1001
#define IDC_PORTNUM                     1002
#define IDC_TEXT                        1003

jwatte's picture


//  chatclient.cpp
//  This file is an example of how to write a client program 
//  using the Etwork networking message API.
//  It is intended to communicate with a server running 
//  the "chatserver.cpp/chathost.cpp" code, over TCP or UDP.
#include "etwork/etwork.h"
#include "etwork/timer.h"
#include "etwork/errors.h"
#include "resource.h"

jwatte's picture


The sample client program in the Etwork networking library.

jwatte's picture

Online Browsable Source-code

These pages contain the source code for Etwork version 0.4, in online browsable form.

jwatte's picture

Static reflection in C++ using minimal repetition

Don't Repeat Yourself.

That's a great rule for writing code. If you find that you repeat yourself in code, then you're probably doing something wrong. Writing code should be about expressing what's unique about something, not filling out standard forms of data. (Copy-and-Paste coding is the worst version of this)

Unfortunately, when it comes to providing serialization and editing information about classes in C++, the language falls down. In C#, and other .NET languages, and even in Java, reflection is rich and allows you to build nice, automated editors and serializers using minimal mark-up. Also, if you need mark-up, that mark-up can be done in-place where members are defined, typically using custom attributes.

jwatte's picture

.NET Reflection, Boxing, and Properties in XNA games

System.Reflection is great! You can find all public properties on an object, and manipulate them programmatically, without knowing the exact type of the object. You can also treat properties generically, by passing a PropertyInfo and object instance around. This allows you to build generic animation systems (similar to how the Windows Presentation Foundation dynamic animatable properties work).

Syndicate content