doucan4873 2017-11-21 08:58
浏览 100

如何在Golang中用C#和Server编写Tcp / ip网络,以进行统一的多人跳棋游戏。

I'm making Checkers game in unity for android platform. I was given a task to make this game multiplayer and implement TCP/IP network in C# language, and for Server side I have to use Golang. I nearly finished the game itself, but I don't know nothing about server and tcp, how to implement them for my game. is there any way to start that or tutorials to show how to do that ? Any advice will be great ! Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongshi1880 2017-11-21 15:58
    关注

    Okay, so, you're trying to build the server-client communication of your app. When we talk about communication, there is a keyword that always appear: socket. In short, sockets allow communication between two different processes on the same or different machines. There are different types of sockets, you can check differences between some of them here and here.

    To establish a communication channel, the steps that are needed on the client side are:

    1. Create socket through socket() system call.
    2. Connect the socket to the server address using connect() system call.
    3. Send and receive data through read() and write().

    And on the server side are:

    1. Create socket through socket() system call.
    2. Bind the socket to an address (e.g. ip:port) using the bind() system call.
    3. Listen for connections with listen() system call.
    4. Accept a connection with accept() system call.
    5. Send and receive data through read() and write().

    Normally, on the server side you want to create a socket pool, in order to achieve more performance (instead of creating a new socket for each player that connects to your server).

    Check the image below to see how is the interaction flow between server and client. In your case, requests are messages sent from players to the server with game info (e.g., the move a player did in its turn). Messages that go from server to the players can be just an ACK or they can be a more elaborated information (e.g., the move an opponent did in its turn).

    enter image description here

    Now, the transmission of data: Since Internet just can handle bits and does not understand what an object or a struct are, we have to Serialize and Deserialize the messages when they go out to the Internet or arrive from it. To achieve this in an easy you can use Protocol Buffers, a tool built by Uncle Google that simplifies this process and that can be used by different languages (e.g., Go and C#).

    Take some examples below on how to build a server-client app in Go and C#, separately. You can then choose which parts do you need to your project:

    Hope it helped!

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮