SUPER简单的C ++多线程服务器? [英] SUPER simple C++ multi-threaded server?

查看:93
本文介绍了SUPER简单的C ++多线程服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在独自开发一款简单的基于文本的RPG游戏,可以与我的弟弟和最多1〜2个朋友一起在线玩.我已经完成了大部分RPG的准备工作并准备就绪,因此在服务器和客户端正常工作之前,我不希望进一步.

到目前为止,我已经阅读了一些Winsock教程,尝试了SFML和Boost.Asio,并阅读了数十个有关创建多线程网络的课程(包括本站点的课程),但是所有这些都太复杂了,难以使用.我具有基本的编程经验,并且了解联网的逻辑,但似乎编程网络仍然困扰着我.

我想有一个客户端和一个服务器程序,用于通过TCP进行IP多线程(仅用于发送聊天消息和可变数据).我只需要最简单的TCP多线程服务器/客户端,仅此而已(仅此而已,否则我可能无法使其编译).

有没有人可以为我的基于文本的游戏中使用的服务器和客户端提供C ++的超简单框架?我很乐意在游戏中为您效劳(即使只有大约3个人会看到此功劳).即使它们不是现实世界中非常实用的客户端和服务器程序,也将不胜感激.

我尝试从此处运行一个教程( http://www. tidytutorials.com/2009/12/c-winsock-example-using-client-server.html [ \ TheServer \ WinServer.cpp ||在函数' int main(int,char * *)':| C:\ TheServer \ WinServer.cpp | 75 |警告:签名 无符号整数表达式| C:\ TheServer \ WinServer.cpp | 84 |错误:跳转到标签' FINISH' | C:\ TheServer \ WinServer.cpp | 62 |错误:从这里| C:\ TheServer \ WinServer.cpp | 69 |错误:' int addr_size' |的初始化交叉 C:\ TheServer \ WinServer.cpp | 84 |错误:跳转到标签' FINISH' | C:\ TheServer \ WinServer.cpp | 58 |错误:从此处| C:\ TheServer \ WinServer.cpp | 69 |错误:' int addr_size' |的初始化交叉 C:\ TheServer \ WinServer.cpp | 84 |错误:跳转到标签' FINISH' | C:\ TheServer \ WinServer.cpp | 43 |错误:从这里| C:\ TheServer \ WinServer.cpp | 69 |错误:' int addr_size' |的初始化交叉 C:\ TheServer \ WinServer.cpp | 84 |错误:跳转到标签' FINISH' | C:\ TheServer \ WinServer.cpp | 34 |错误:从这里| C:\ TheServer \ WinServer.cpp | 69 |错误:' int addr_size' |的初始化交叉 C:\ TheServer \ WinServer.cpp | 84 |错误:跳转到标签' FINISH' | C:\ TheServer \ WinServer.cpp | 25 |错误:从这里| C:\ TheServer \ WinServer.cpp | 69 |错误:' int addr_size' |的初始化交叉 || ===构建完成: 15 错误, 1 警告=== |



我没有触摸原始的.cpp文件;我所做的只是手动将头文件添加到项目文件夹中(以防万一程序没有找到它们),但是即使在这样做之前,我也遇到了同样的错误.我已经尝试了另外3个用于多线程服务器的预制.cpp文件,只是试图让其中一个起作用,但是每个文件给我一个不同的错误,并且不允许我编译. class ="h2_lin">解决方案

您阅读了数十本教程仍没有找到出路吗?

单独尝试,首先执行线程处理,然后进行套接字编程.然后尝试使它们破损.

阅读不是每个人的更好解决方案,有些人对看到结果感到满意.所以,开始编程

[添加您的更新]
首先,您没有说您正在使用什么编译器.
请执行以下
从微型软件站点下载Visual Studio C ++ Express版本.

运行Visual C ++;
创建一个新的项目名称服务器.

然后在该项目中添加WinServer.cpp.
在项目属性中(您将在项目"菜单中获得它),单击配置">链接器">输入树节点".您将在右侧获得一个列表.在附加依赖项"输入框中,输入 Ws2_32.lib
编译并运行它.

从程序文件中运行Visual C ++的新实例

创建一个新的项目名称客户端
然后将WinClient.cpp添加到项目中

在项目属性中(您将在Project菜单中获得它),单击Configuration> linker>输入树节点.您将在右侧获得一个列表.在附加依赖项"输入框中,输入 Ws2_32.lib 
编译运行它并让它运行.
编译并运行客户端.


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.

解决方案

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>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.


这篇关于SUPER简单的C ++多线程服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆