3

I am developing a game in Flex.
There are both AIR and Web versions of this game. AIR app would connect to a server using a UDP socket on a port. The purpose of the Web version is to allow users to play when they are at work, or on a computer behind some firewall/proxy that blocks some ports. So the web would connect to a server using http connection on port 80.

The server code answering the http connections would be a java servlet that uses BlazeDS. But if any of you find it more easier to explain for a C# server code(webservices or whatever), it would be ok . The server code answering the UDP requests would be a simple class listening for socket connections.

My problem is I don't know how to put UDP and http code together. If there are 5 AIR clients, and 5 Web clients, they all need to meet in the server in some common collection variable, so that I can update all clients with latest info. Who is going to instantiate the class that listens for sockets? And when?

So to summarize:
1. Do I need a dedicated server to achieve what I want?
2. Who will instantiate the udp handling class and when?
3. Is it even possible to keep the udp handling class and the servlet for http connections together? If there would not be http, I wouldn't even need tomcat. But http and udp code need to stay together, so that I can update the players collection. Is it possible to instantiate the UDP handling class and tell it to listen for socket when the servlet is deployed on the server...or something like that?

Any advices are more then welcome.
Thanks in advance,
Miha

4

1 回答 1

1

http 和 udp 代码需要保持在一起

不,他们没有。它们是游戏数据的传输机制,因此它们应该是透明的。您的 UDP 和 HTTP 服务器应该连接到您的游戏后端,具体方式取决于您。它可以在内存中,直接从您的后端代码使用 HTTP 和 UDP(套接字)模块,或者它可以使用某种服务(因此您可以让其他通道与同一后端通信)。

此游戏后端不直接连接到用户,而只与 UDP 和 HTTP 模块对话。

然后从这个后端处理从 HTTP 和 UDP 收到的消息,并通过同一通道发送响应。

例子:

  1. AIR-client 1 向 UDP 服务器发送一个有效的登录消息。
  2. UDP 服务器将登录消息转发到游戏后端。
  3. 游戏后端向 UDP 服务器返回成功结果消息
  4. UDP 服务器将结果消息转发给 AIR-client 1。

示例 2:

  1. 现在,恰好已经登录的 HTTP 客户端 1 请求所有当前登录的用户。它通过 HTTP 向 HTTP 服务器请求。
  2. HTTP 服务器将此请求转发到游戏后端。
  3. 游戏后端向 HTTP 服务器返回信息
  4. HTTP 服务器向客户端返回响应。
于 2012-12-20T10:33:24.553 回答