使用PythonAnywhere作为游戏服务器 [英] Using PythonAnywhere as a game server

查看:208
本文介绍了使用PythonAnywhere作为游戏服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个回合制游戏,我希望实现客户端 - 服务器风格的网络。我真的只需要发送几个对象的位置和其他一些易于编码的数据。我对网络相当陌生,尽管我已经编写了一些基本的东西在socket中并且是扭曲的。现在,我需要能够将数据发送到不在本地网络上的计算机,而且由于我没有管理员访问路由器的功能,所以无法进行端口转发,而且我也不能完全肯定会做的伎俩,因为我从来没有做过。所以,我正在考虑运行一些瓶颈或瓶子或Django等代码PythonAnywhere。客户端然后将数据发送到PythonAnywhere上的服务器代码,当转过来的时候,另一个客户端就会查找它在服务器上需要的信息。我想那个服务器就像一个简单的getter和setter方法一样只是一个数据库。我的问题是如何执行?我的客户端程序上的Socket代码是否可以与PythonAnywhere上的Flask代码进行通信?

使服务器。 PythonAnywhere支持WSGI,这意味着正常的HTTP请求/响应交互 - GET,POST等。这对于传统网页或Web应用程序来说非常合适。

如果您的客户端需要使用非HTTP协议的动态双向连接,使用原始套接字甚至websocket,PythonAnyhwere目前不支持。


I'm building a turn-based game and I'm hoping to implement client-server style networking. I really just need to send the position of a couple of objects and some other easily encodable data. I'm pretty new to networking, although I've coded some basic stuff in socket and twisted. Now, though, I need to be able to send the data to a computer that isn't on my local network, and I can't do port forwarding since I don't have admin access to the router and I'm also not totally sure that would do the trick anyways since I've never done it. So, I was thinking of running some Flask or Bottle or Django, etc. code off PythonAnywhere. The clients would then send data to the server code on PythonAnywhere, and when the turn passed, the other client would just go look up the information it needed on the server. I guess then the server would act as just a data bank with some simple getter and setter methods. My question is how can this be implemented? Can my Socket code on my client program talk to my Flask code on PythonAnywhere?

解决方案

It depends what sort of connection your clients need to make to the server. PythonAnywhere supports WSGI, which means "normal" HTTP request/response interactions -- GET, POST, etc. That works well for "traditional" web pages or web apps.

If your client side needs dynamic, two-way connections using non-HTTP protocols, using raw sockets, or even websockets, PythonAnyhwere doesn't support that at present.

这篇关于使用PythonAnywhere作为游戏服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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