Click here to Skip to main content
Sign Up to vote bad
good
See more: C++GameServerTCP/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:52
Pikky86196
Edited 24 Apr '12 - 10:23

Comments
Pablo Aliskevicius - 24 Apr '12 - 2:27
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 - 24 Apr '12 - 3:07
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 - 24 Apr '12 - 21:08
Check my updated answer
Pikky86 - 24 Apr '12 - 21:54
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

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  
Comments
Pikky86 - 24 Apr '12 - 2:01
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 - 24 Apr '12 - 2:14
tell me at least you did simple thread program and socket program.
Chuck O'Toole - 24 Apr '12 - 9:44
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 - 24 Apr '12 - 23:15
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 - 24 Apr '12 - 2:18
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 - 24 Apr '12 - 2:21
in that case i would suggest you to post the error you are getting. please also mention the compiler you are using
Mohibur Rashid - 24 Apr '12 - 2:23
and dont feel stupid, we all have passed that stage
Pikky86 - 24 Apr '12 - 16:23
I went ahead and updated my question, though I'm not sure if it'll be much help...
Pikky86 - 24 Apr '12 - 2:34
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
Your Filters
Interested
Ignored
     
0 OriginalGriff 318
1 Sergey Alexandrovich Kryukov 143
2 Mohammed Hameed 123
3 Santhosh G_ 108
4 Lohith Korupolu 85
0 Sergey Alexandrovich Kryukov 8,266
1 OriginalGriff 6,306
2 CPallini 3,528
3 Rohan Leuva 2,703
4 Maciej Los 2,234


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