Click here to Skip to main content
15,885,869 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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:

C++
\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
Updated 24-Apr-12 10:23am
v2
Comments
Pablo Aliskevicius 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 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 24-Apr-12 21:08pm    
Check my updated answer
Pikky86 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

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
XML
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.
compile it and run the client.
 
Share this answer
 
v3
Comments
Pikky86 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 24-Apr-12 2:14am    
tell me at least you did simple thread program and socket program.
Chuck O'Toole 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 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 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.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900