Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Game Server TCP/IP , +
I'm working on a simple, text-based console RPG game by myself to play online with my little brother and maybe 1~2 friends at most. I've got the RPG mostly set up and ready to go, so I don't want to go any further until I get a server and client working.
 
So far I've read several Winsock tutorials, tried SFML and Boost.Asio, and read dozens of lessons on creating multithreaded networks (including lessons on this site), but all of them were too complicated to use. I have basic programming experience and understand the logic of networking, but it seems programming networking is still over my head.
 
I'd like to have a client and a server program for IP multi-threading over TCP (just for sending chat messages and variable data). I only need the simplest possible TCP multi-threaded server/client, and nothing more (anything more and it'll just go over my head, or I might not be able to make it compile).
 
Is there anyone who can provide a super simple framework in C++ for a server and client that I could use for my text based game? I'd be happy to credit you for it in the game (even though only about 3 people will see the credit). Even if they're not very practical client and server programs in the real world, any help would be most appreciated.
 
Edit: I tried running a tutorial from here (http://www.tidytutorials.com/2009/12/c-winsock-example-using-client-server.html[^]), and when I compiled the Server application I got this error message in CodeBlocks:
 
\TheServer\WinServer.cpp||In function 'int main(int, char**)':|
C:\TheServer\WinServer.cpp|75|warning: comparison between signed and unsigned integer expressions|
C:\TheServer\WinServer.cpp|84|error: jump to label 'FINISH'|
C:\TheServer\WinServer.cpp|62|error:   from here|
C:\TheServer\WinServer.cpp|69|error:   crosses initialization of 'int addr_size'|
C:\TheServer\WinServer.cpp|84|error: jump to label 'FINISH'|
C:\TheServer\WinServer.cpp|58|error:   from here|
C:\TheServer\WinServer.cpp|69|error:   crosses initialization of 'int addr_size'|
C:\TheServer\WinServer.cpp|84|error: jump to label 'FINISH'|
C:\TheServer\WinServer.cpp|43|error:   from here|
C:\TheServer\WinServer.cpp|69|error:   crosses initialization of 'int addr_size'|
C:\TheServer\WinServer.cpp|84|error: jump to label 'FINISH'|
C:\TheServer\WinServer.cpp|34|error:   from here|
C:\TheServer\WinServer.cpp|69|error:   crosses initialization of 'int addr_size'|
C:\TheServer\WinServer.cpp|84|error: jump to label 'FINISH'|
C:\TheServer\WinServer.cpp|25|error:   from here|
C:\TheServer\WinServer.cpp|69|error:   crosses initialization of 'int addr_size'|
||=== Build finished: 15 errors, 1 warnings ===|
 
I didn't touch the original .cpp file; All I did was manually add the header files to the project folder (just in case the program didn't have them already located), but I got this same error even before doing that. I've tried about 3 other pre-made .cpp files for multithreaded servers, just to try and get ONE of them to work, but each gives me a different error(s) and won't let me compile.
Posted 23-Apr-12 18:52pm
Pikky86196
Edited 24-Apr-12 10:23am
v2
Comments
Pablo Aliskevicius at 24-Apr-12 2:27am
   
You say:
"super simple framework in C++ for a server and client"
IMHO, C++ is seldom super-simple; I use C++ mostly for heavy lifting. For RAD (Rapid Application Development), I'd suggest .NET.
Just my two bits...
Pablo.
Pikky86 at 24-Apr-12 3:07am
   
I'd agree that C++ isn't a simple language. The reason I'm using it is because it's the only language I'm semi-familiar with, but I'm sure .NET would take less time to do what I'm trying to do.
Mohibur Rashid at 24-Apr-12 21:08pm
   
Check my updated answer
Pikky86 at 24-Apr-12 21:54pm
   
Thank you so much!!! Ah, it was so simple! But I couldn't get it to work before at all. Now it compiles right away~

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You read dozens of tutorial still didn't find a way out?
 
Try separately, first do how to do threading then do socket programming. then try to marge them.
 
Reading is not better solution for everyone, some people is comfortable with seeing result. so, start programming
 
[adding with your update]
first of all you didn't say what compiler you are using.
do the following
download visual studio c++ express version from micro soft site.
 
run visual c++;
create a new project name server.
 
then add the WinServer.cpp in that project.
in the project properties (you will get it in Project menu) click on Configuration>linker>Input tree nodes. you will get a list on the right. in the Additional Dependencies input box write Ws2_32.lib
compile it run it and let it run.
 
run a new instance of visual c++ from your program files
 
create a a new project name client
then add WinClient.cpp to the project
in the project properties (you will get it in Project menu) click on Configuration>
  Permalink  
v3
Comments
Pikky86 at 24-Apr-12 2:01am
   
Yeah, I still didn't find a way out. All the beginner lessons I found in networking are waaay over my head. I'm only experienced in basic console programming.
Mohibur Rashid at 24-Apr-12 2:14am
   
tell me at least you did simple thread program and socket program.
Chuck O'Toole at 24-Apr-12 9:44am
   
It's only over your head because you haven't done it yet. Everything was over your head at some point and that was true for us all. As Captain Kirk said, "we learn by doing", so take one of those examples and start using it and modifying it to do what you want it to do. Post messages here (as new topics) when you run into specific problems and you'll get some help.
Pikky86 at 24-Apr-12 23:15pm
   
Thanks for quoting Star Trek. I didn't think I could do it, but now I'm confident that anything is possible :D I finally got a basic server/client working thanks to Mohibur and I'm gonna start working with that.
Pikky86 at 24-Apr-12 2:18am
   
Yes, I've tried it. I've actually downloaded several pre-made .cpp files from various tutorials for making a server and a client, but couldn't get a single one of them to compile successfully - it just made me feel even stupider. I'm not sure if it's been header issues or what, but I've been much luckier with other things than networking.
Mohibur Rashid at 24-Apr-12 2:21am
   
in that case i would suggest you to post the error you are getting. please also mention the compiler you are using
Mohibur Rashid at 24-Apr-12 2:23am
   
and dont feel stupid, we all have passed that stage
Pikky86 at 24-Apr-12 16:23pm
   
I went ahead and updated my question, though I'm not sure if it'll be much help...
Pikky86 at 24-Apr-12 2:34am
   
Thx, I'll try it again with SFML (as before) and another new tutorial I found as well and update the question tomorrow with the errors I'm getting in the compiler.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 369
1 Sergey Alexandrovich Kryukov 365
2 Maciej Los 285
3 George Jonsson 185
4 King_Fisher 160
0 Sergey Alexandrovich Kryukov 10,934
1 Maciej Los 5,614
2 OriginalGriff 5,603
3 CPallini 3,879
4 BillWoodruff 3,579


Advertise | Privacy | Mobile
Web04 | 2.8.141030.1 | Last Updated 24 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100