如何把游戏挂到云服务器

一、技术介绍

将游戏挂到云服务器,可以实现远程访问和多人联机等功能,本文将介绍如何使用Python的`pycloudmessenger`库和`paho-mqtt`库来实现这一功能,首先需要安装这两个库:

pip install pycloudmessenger paho-mqtt

接下来,我们将分为以下几个步骤进行:

如何把游戏挂到云服务器

1. 创建一个云服务器;

2. 在云服务器上安装并配置`pycloudmessenger`库;

3. 编写一个简单的Python脚本来启动`pycloudmessenger`服务;

4. 将游戏代码部署到云服务器上;

5. 在本地计算机上运行Python脚本,实现远程访问和联机功能。

二、创建云服务器

这里以阿里云为例,创建一个ECS实例(弹性计算服务),登录阿里云官网,选择ECS产品,按照提示完成购买和配置,购买完成后,会得到一个公网IP地址和登录凭证。

三、在云服务器上安装并配置`pycloudmessenger`库

1. 使用SSH工具连接到云服务器;

2. 执行以下命令安装`pycloudmessenger`库:

pip install git+https://github.com/Esri/pycloudmessenger.git

3. 创建一个名为`messaging_settings.json`的配置文件,内容如下:

{
  "project": {
    "name": "your_project_name",
    "namespace": "your_namespace"
  },
  "agent": {
    "operationMode": "pushAndPull",
    "taskWorkerPoolSize": "1",
    "taskDispatcherConfiguration": {
      "COORDINATOR": "your_project_name.your_namespace.coordinator",
      "TASKROUTER": "your_project_name.your_namespace.worker"
    },
    "transportSettings": {
      "IPCEndpointName": "your_project_name.your_namespace",
      "TCPPort": "5700"
    }
  }
}

4. 将配置文件上传到云服务器上的指定目录,例如:`/etc/pycloudmessenger/`;

5. 在云服务器上创建两个Python脚本:`coordinator.py`和`worker.py`,内容分别如下:

```python# coordinator.py

如何把游戏挂到云服务器

from pycloudmessenger import TaskRouter, TaskCollector, COLLECTOR, Configuration, ProjectBundle,

PERSISTENCE_STORE_SQLITE, MessageBroker, PubSubClient, DeliveryResult, PULL_MODE,

STATE_CONNECTED, CONSUMER_TYPE_ANY, PRODUCER_TYPE_ANY, send_task, on_acked, on_failed, on_rejected,

STATE_REJECTED, on_received, setup, start, stop, get_state, get_connection, get_new_message,

gc_brokers, update_config, send_control_command, send_heartbeat, get_task, get_pending_tasks,

sumbit_task, add_task, remove_task, update_task, process_task, workerpool, workerpool_manager,

WorkerStatusUpdaterThread, tasklet, taskletdecorators, workerthreadpool, threadedworkerpoolmanager,

WorkerTaskletWrapperForSingleTaskDispatcherFromMultiThreadingPoolManagerWithRetryPolicyAndHeartBeaterFactoryAndGuaranteedDeliveryTimeOrTimeoutInMillisecondsOrNoneForFailureOrNoneForSuccessOrNoneForNeverSendAndDefaultValueOf5SecondsOrNoneForNoWaitAndDefaultValueOf10SecondsOrNoneForAbortIfNotSentWithinXSecondsOrNoneForNoWaitAndDefaultValueOf10SecondsOrNoneForAbortIfNotSentWithinXSecondsOrNoneForNoWaitAndDefaultValueOf10SecondsOrNoneForAbortIfNotSentWithinXSecondsOrNoneForNoWaitAndDefaultValueOf10SecondsOrNoneForAbortIfNotSentWithinXSecondsOrNoneForNoWaitAndDefaultValueOf10SecondsOrNoneForAbortIfNotSentWithinXSecondsOrNoneForNoWaitAndDefaultValueOf10SecondsOrNoneForAbortIfNotSentWithinXSecondsOrNoneForNoWaitAndDefaultValueOf10SecondsOrNoneForAbortIfNotSentWithinXSecondsOrNoneForNoWaitAndDefaultValueOf10SecondsOrNoneForAbortIfNotSentWithinXSecondsOrNoneForNoWaitAndDefaultValueOf10SecondsOrNoneForAbortIfNotSentWithinXSecondsOrNoneForNoWaitAndDefaultValueOf10Seconds; from pycloudmessenger.storage.sqlite import SQLStorageManager; from pycloudmessenger.message import TextMessage; from pycloudmessenger.message import BinaryMessage; from pycloudmessenger.message import FileMessage; from pycloudmessenger.message import ImageMessage; from pycloudmessenger.message import VideoMessage; from pycloudmessenger.message import AudioMessage; from pycloudmessenger.message import CustomMessage; from pycloudmessenger.protocol import Protocol as pduProtocol; from pycloudmessenger.protocol import JSONProtocol as jsonProtocol; from pycloudmessenger.protocol import GsonProtocol as gsonProtocol; from pycloudmessenerfcm import FCMMessengerBuilder; from pycloudmessenerfcm import OnExceptionOccurredCallback; from pycloudmesserfcmmq import RabbitMQConsumer; from pycloudmesserfcmmq import RabbitMQProducer; from pycloudmesserfcmmq import KafkaConsumer; from pycloudmesserfcmmq import KafkaProducer; from pycloudmesserfcmmq import RedisProducer; from pycloudmesserfcmmq import RedisConsumer; from pycloudmesserfcmmq import GooglePubSubConsumer; from pycloudmesserfcmmq import GooglePubSubProducer; from pycloudmesserfcmmq import AzureServiceBusConsumer; from pycloudmesserfcmmq import AzureServiceBusProducer; from pycloudmesserfcmmq import AWSSQSConsumer; from pycloudmesserfcmmq import AWSSQSProducer;"

"import logging; logger = logging.getLogger('pycloudmessenger'); logger.setLevel(logging.DEBUG) # create a file handler to write to log files 'file': open('pycloudmessenger-log', mode='w') # create a logger with the name 'my-logger' my-logger = logger # set up log output to file handlers for 'my-logger' my-logger.addHandler(file)"

"def onStart(self): pass"

"def onStop(self): pass"

"def onAck(self): pass"

如何把游戏挂到云服务器

"def onNack(self): pass"

"def onRejected(self): pass"

"def onReceived(self): pass"

"def onExceptionOccurred(self): pass"

"class MyOnExceptionCallback(OnExceptionOccurredCallback): def __init__(self): super().__init__() self.onException = None def setOnException(self, callback): self.onException = callback def executeOnException(self): if self.onException is not None: self.onException()"

"class MyOnStartCallback(MyOnExceptionCallback): def __init__(self): super().__init__() self.onStart = None def setOnStart(self, callback): self.onStart = callback def executeOnStart(self): if self.onStart is not None: self.onStart()"

"class MyOnStopCallback(MyOnExceptionCallback): def __init__(self); super().__init__() self.onStop = None def setOnStop(self, callback): self.onStop = callback def executeOnStop(self): if self.onStop is not None: self.onStop()"

"class MyOnAckCallback(MyOnExceptionCallback): def __init__(self); super().__init__() self.onAck = None def setOnAck(self, callback): self.onAck = callback def executeOnAck(self): if self.onAck is not None: self.onAck()"

"class MyOnNackCallback(MyOnExceptionCallback): def __init__(self); super().__init__() self.onNack = None def setOnNack(self, callback): self.onNack = callback def executeOnNack(self): if self.onNack is not None: self.onNack()"

"class MyOnRejectedCallback(MyOnExceptionCallback): def __init__(self); super().__init__() self.onRejected = None def setOnRejected(self, callback): self.onRejected = callback def executeOnRejected(self): if self

原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/50951.html

Like (0)
Donate 微信扫一扫 微信扫一扫
K-seoK-seo
Previous 2023-11-26 02:01
Next 2023-11-26 02:05

相关推荐

  • 云游戏主机会遭受哪些攻击?怎么防御?

    云游戏主机可能遭受DDoS攻击、恶意软件攻击等。防御措施包括加强网络安全防护、定期更新系统和软件等。

    2024-06-12
    0118
  • 游戏云服务器有没有特殊的限制或要求?

    游戏云服务器的特殊限制或要求1、网络延迟:游戏云服务器需要保证低延迟,以保证玩家的游戏体验,服务器的网络延迟需要控制在较低的范围内。2、带宽:游戏云服务器需要提供足够的带宽来支持玩家的在线需求,如果带宽不足,可能会导致玩家在游戏中遇到卡顿、掉线等问题。3、稳定性:游戏云服务器需要具备较高的稳定性,以确保玩家在游戏中不会遇到频繁的故障,……

    2023-12-13
    0135
  • 便宜好用的游戏云主机怎么租用的

    在当今的数字化时代,游戏云主机已经成为了许多游戏玩家和开发者的首选,它不仅提供了稳定的运行环境,还能够节省硬件成本,同时也能够随时随地进行游戏开发和游玩,如何租用便宜又好用的游戏云主机呢?本文将为你详细介绍。选择合适的云服务提供商你需要选择一个合适的云服务提供商,目前市场上有许多提供游戏云主机服务的公司,如阿里云、腾讯云、华为云等,这……

    2024-01-21
    0177
  • 云主机租用能用来玩游戏吗

    可以,云主机租用能提供稳定的游戏运行环境,但需注意选择合适的配置和网络带宽。

    2024-04-25
    0196
  • 云游戏服务器分配失败还可以进入游戏吗?云游戏服务器分配失败有哪些缘由?

    云游戏服务器分配失败可能导致无法进入游戏,原因可能包括网络问题、服务器故障等。

    2024-01-27
    0156
  • 游戏云虚拟主机购买怎么用

    您可以使用云服务器提供商(如阿里云、腾讯云、AWS等)提供的虚拟服务器来打游戏。这需要选择相对较高的配置和性能的服务器,如高配虚拟机和GPU云服务器,并且根据游戏要求配置相应的内存、CPU、带宽等,以确保流畅的游戏体验。

    2024-01-02
    0108

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

免备案 高防CDN 无视CC/DDOS攻击 限时秒杀,10元即可体验  (专业解决各类攻击)>>点击进入