Unity Hand Tour < three > chat room source based on Unity+java

Source: Internet
Author: User

http://blog.csdn.net/janeky/article/details/17233199

    • Project Introduction

This is a simple unity project that implements the most basic chat room Group chat feature. After you log in to a chat room, users can enter information to speak and others can receive messages. The player can also change the nickname. The project details the process of the front-end socket communication, encoding, and parsing of the binary stream.

    • The main objectives of the project are several:

1. Realizing Unity's front-end communication system
2. The application of learning Protobuf

    • The final effect

    • Front

A. Network communication NetClient.cs
TCP communication using C #. During initialization, the connection is established. Then there is no data at the end of each frame function update () Detection service on unity. In order to avoid sticky packets and other situations, the front and back end of the message body is such structure: the length of the message body + the content of the message body. In the process of parsing, the length of the message body is parsed, and then waits for sufficient binary stream, and finally decodes the entity object with Protobuf-net.

The process of sending a message is just the opposite. Serializes an entity object into a binary stream and then assembles it into a message body, sent to the backend

B.ui Design
The UI of the program is made using Ngui. The interface layout is relatively simple. Nickname box, message list, message box. The name is good, the layout is good, then the commit function is processed in the program, and the message is sent to the backend. When the back-end message is pushed over, it is displayed in the message list. There is no time to perfect the place, is currently not supported in Chinese, has not been timely fix font set.

    • Back end

The service side adopts Netty Network framework, which can realize a service side quickly and efficiently. In accordance with Netty's basic process, we can quickly build good one servers. The main task is to encode and decode the process. According to the message body structure above, we also parse the length first, then read the memory, and finally decode it with PROTOBUF. The server's business logic is simple, that is, the broadcast of the chat information. When the client connects, the connection is saved so that all connected broadcasts are made easy to follow.

    • Summarize

The source of the project has been placed on GitHub, welcome to consult, suggestions. Have any questions welcome to explore [email protected]

Unity Hand Tour < three > chat room source based on Unity+java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.