Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 SimpleSockets
Index -> Programming, C++ -> C++ Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rizzix




PostPosted: Thu Mar 17, 2005 11:55 pm   Post subject: SimpleSockets

I created a small, little, very simplistic, framework that is cross-platform compatible, for networking in c++. It's very easy to use, just take a look at the examples (TestClient.cpp and TestServer.cpp). It does poor error checking so I suggest, you be careful, or extend/modify it, or simply wait for another version. attached are the files. enjoy!

EDIT: As of ver 0.7 onwards, the error handling has been improved significantly



SimpleSockets.zip
 Description:
version: 0.8

Download
 Filename:  SimpleSockets.zip
 Filesize:  14.1 KB
 Downloaded:  303 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Fri Mar 18, 2005 2:50 pm   Post subject: (No subject)

Version 0.3 fixes a lot of annoying bugs and issues. For example sending an interger in windows now actually sends an interger. Previously it would send a char* representation of an interger. The same goes for short int and long int. unix users need not worry, both previous versions (0.1 and 0.2) sent the actual data type and not string represntations. Also added is char* support, yes you can now transfer c-strings. internally this is handled by first calculating the string length then sending the length data first (as int) then sending the string right after (includind the trailing '\0'). the inverse is done for receiving strings.

Floating point support comming out in version 0.4. as well as auto endian conversions.
Andy




PostPosted: Sat Mar 19, 2005 12:00 pm   Post subject: (No subject)

wow.. thats nice.. thx alot.. now i can actually make my friends the card game they've begging me to make...
rizzix




PostPosted: Sat Mar 19, 2005 9:02 pm   Post subject: (No subject)

Version 0.4
Yep, well as promised, this version has floating point support. It also provides network aware endianess: your network programs will communicate well between x86 and ppc & alike. The catch here is that 0.4 does not currently support sending endian aware floating points.. yea you'd have to wait for another version for that.

Also added are new functions: sendRaw(void*, int size) & recvRaw(void*, int size) as well as sendLine(char*, int len) and recvLine(char*, int len). I dont recommend using sendRaw/recvRaw at all (they are not endian aware functions).

sendLine/recvLine can be used instead of << and >> operators. the bonus to these functions is that it will not send the additional int (the length of the string).

there is also a:
void* recvRaw(int size);
and
char* recvLine(int len);

which return a dynamically allocated char*/void* instead of passing it one yourself.

ALSO NOTE: all int are sent internally as long int. on most platforms this should not be much of a difference. correct me if i'm wrong, but i think, it's usually the long long int that are 64-bit, while the long int and int are 32-bit.
Andy




PostPosted: Sun Mar 20, 2005 2:28 pm   Post subject: (No subject)

yup it is.. to bad there isnt long long long int lol
rizzix




PostPosted: Sun Mar 20, 2005 2:58 pm   Post subject: (No subject)

there's a long double that is 96 bits on one of my computers. Shocked i'm not going to add support for it though.. cuz it's not the same size on all platforms. ugh.
wtd




PostPosted: Sun Mar 20, 2005 4:09 pm   Post subject: (No subject)

Yes, "long double" is extremely hardware-dependent. Any of the native types are.
rizzix




PostPosted: Mon Mar 21, 2005 11:46 pm   Post subject: (No subject)

Version 0.7
So much has been added, that I had to bump the version number to 0.7, just to relatively show the amount change.

I recommend this to all! Not only is this version much reliable (some heavy testing done), it is much much safer than all the previous versions.

This version includes:
Error handling through Exceptions (read the Socket.h and ServerSocket.h to know which methods throw what exception)

A mechanism to send objects over the network (SocketSerializable.h) Look at the examples for details on how to use this feature.

Support for long long.

All functions and operators are endian aware! Yes I got the floating point endianess into this version (for both float and double), thanks to the IEEE docs and gamedev.net with their fantastic tutorial.

NOTE: sendRaw/recvRaw functions are intentionally not endian aware.
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Tue Mar 22, 2005 1:46 am   Post subject: (No subject)

This is awsome, i'm looking at using it in the sim i'm writing Smile
rizzix




PostPosted: Mon Jan 23, 2006 4:52 pm   Post subject: (No subject)

version 0.8
This is a bug fix release. Some issues with windows and the new GCC compiler.

One major bug has been fixed: it wouldn't throw any IOExceptions before, due to a logic error.

New feature: I've added in-code documentation and provided a Doxyfile. You can now compile the docs like this:
code:
doxygen

GCC Windows users make sure to add a -lwsock32 option as part of your compiler arguments.
Justin_




PostPosted: Mon Jan 23, 2006 9:24 pm   Post subject: (No subject)

Wow, it works great now. Thanks rizzix! SimpleSockets rock! Great job man!
Justin_




PostPosted: Tue Feb 14, 2006 4:06 pm   Post subject: (No subject)

Wait a second, am I doing something wrong or did you change the source again. On winxp I can't compile anything from the example folder.

code:

g++ -lwsock32 -I.. -I. ../*.cpp chatserver.cpp -o chatserver


comes up with a series of undefined references: "ntohl@4", "htons@4", "connect@12", "socket@12", and "inet_addr@4".
rizzix




PostPosted: Tue Feb 14, 2006 4:11 pm   Post subject: (No subject)

it should be (since you're on windows):
code:
g++ -lwsock32 -I.. -I. ..\*.cpp chatserver.cpp -o chatserver
Justin_




PostPosted: Tue Feb 14, 2006 5:13 pm   Post subject: (No subject)

MSDOS automatically corrects the slashes, you can use either or. But I tried it anyway and still same errors.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 14 Posts ]
Jump to:   


Style:  
Search: