Based on Socket IO + Unity Building the Metaverse of Dream of the Red Chamber


The Metaverse of Dream of the Red Chamber has a natural fit with Unity + Socket.IO, both in virtual space and functional design. Using Unity, you can generate and build the foundation of the Metaverse of Dream of the Red Chamber: virtual reality, including real-time dynamic internal generation and external loading of virtual characters, scenes, and various other elements, and can achieve various controls over these elements without delay. The Metaverse space built by Unity has full immersion and diversity; Socket.IO realizes Internet connection, Unity C# script creates Socket.IO client, Unity + Socket.IO connection realizes interpersonal communication, thus jointly realizing digital identity management in the Metaverse of Dream of the Red Chamber. Including virtual identity registration, Unity to achieve login authentication, digital avatar unique distribution; jointly create a network social space including games, business transactions, friends and entertainment, and provide corresponding safety information management for it, which is enough to reflect the special code of conduct and civilization ecology in the Metaverse. In short, Unity + Socket.IO can build a complete system of the Metaverse of Dream of the Red Chamber from the digital technology level.

Share and Cite:

Rong, Z. (2023) Based on Socket IO + Unity Building the Metaverse of Dream of the Red Chamber. Intelligent Information Management, 15, 426-441. doi: 10.4236/iim.2023.156020.

1. The Origin of the Metaverse of Dream of the Red Chamber

1.1. Meta-Universalization Analysis of Dream of the Red Chamber

Dream of the Red Chamber is renowned for its exquisite literary art, profound character descriptions, and rich cultural connotations, and is considered one of the greatest novels in Chinese literature. It represents the peak of Chinese literature, integrating various literary forms such as poetry, opera, prose, and poetry. Its connotation is only rich, naturally forming a vast and colorful universe of Paul’s universe, but people’s understanding and perception of it are very limited. There may be many reasons, but the main reason is that traditional reading methods require high literacy from readers, which means that for people with shallow life experience and low literary literacy, they may not understand or appear boring (Figure 1). So, using modern and innovative means of expression, this great work is presented, allowing everyone to easily enter, experience, quickly perceive, and communicate with the characters described in the book at zero distance, or even transform into a certain character, experiencing the story described in the book, which is the Metaverse of Dream of the Red Chamber. The corresponding changes that are clearly foreseeable after the Metaverse transformation are also a powerful driving force for the birth of the Metaverse of Dream of the Red Chamber (Figure 2) [1] .

1.2. The Functional Design of the Metaverse of Dream of the Red Cham ber

As a vast and complex system, the Metaverse must possess corresponding complex functions. Roblox is the first company to incorporate the functional requirements of the Metaverse into its prospectus. Roblox proposed eight key features of

Figure 1. The negative and positive factors in the original works of Dream of the Red Chamber jointly promote its meta-universalization transformation.

Figure 2. The evolution of the negative factors brought about by the meta-universalization formation in the original works of Dream of the Red Chamber, which is the driving force behind the promotion of the Metaverse of Dream of the Red Chamber.

Figure 3. Functional framework chart of the Metaverse of Dream of the Red Chamber.

the Metaverse, which are actually essential functions that the Metaverse must possess: Identity, Friends, Immersive, Low Friction, Variety, Anywhere, Economy, and Civilization. The same goes for the Metaverse of Dream of the Red Chamber. From initial design, to construction and implementation, to running testing and verification, efforts must be made to achieve these functions, thus presenting the fundamental characteristics of the true Metaverse [2] (Figure 3).

1.3. The Spatial Composition of the Metaverse of Dream of the Red Cham ber

The space of the Metaverse of Dream of the Red Chamber consists of two main parts: the scenes described in the original works and the Redology (academic field devoted the study of Dream of the Red Chamber) Society Forum (a virtual academic forum for the study of Dream of the Red Chamber). There are many opinions in the academic and folk circles regarding the layout of the former, which is the scene depicted in the Dream of the Red Chamber. In addition, the description of the scene in the original works is limited to textual descriptions, which inherently leaves a lot of room for imagination. The research results of Redology that are most in line with the description of the original works Dream of the Red Chamber (Cheng Gao Edition) are adopted here (Figure 4). The latter is a virtual experience space constructed by developers based on the Metaverse ray of Dream of the Red Chamber (Figure 5), but there is actually no fixed sample [3] .

Figure 4. Layout plan of the Metaverse space of Dream of the Red Chamber: content scenes in the original works.

Figure 5. The Metaverse space layout of Dream of the Red Chamber—scenarios of Redology research content.

1.4. The Workflow of the Metaverse of Dream of the Red Chamber

The Metaverse of Dream of the Red Chamber itself is in working condition at all times, and there are no frequent and complicated processes. What this refers to is the client’s entry into the Metaverse of Dream of the Red Chamber and the various tasks that are usually carried out after entry, and they need to strictly follow the prescribed procedures. Otherwise, either you will not be able to enter the Metaverse, or after entering the Metaverse, you will not be able to obtain full physical enjoyment and effective social interaction. Of course, you will not be able to obtain ideal economic benefits in the Metaverse (Figure 6) [4] .

2. The Foundation of Building the Metaverse of Dream of the Red Chamber: Virtual Reality

The foundation of the Metaverse is virtual and augmented reality technology, which allows users to interact with the digital environment. Virtual reality provides a complete digital experience, while augmented reality overlays digital content in the real world. More often than not, the Metaverse is reflected at the level of virtual reality.

Although Dream of the Red Chamber belongs to literary works, depicting people and objects that do not exist in reality, it can also be virtual and make the experience feel real, and can form a complete world. However, virtual reality is different from simulation, it is not just a restoration of the original existence in reality. It can be an artistic creation, and the basic elements that make up this works of art are very rich, and the types are also diverse. Unity3D mainly constructs virtual reality in the Metaverse of Dream of the Red Chamber through the following methods (Figure 7) [5] .

2.1. Unity Generating Virtual Reality Elements

2.1.1. Dynamically Generating Virtual Characters

The exclusive virtual characters depicted in the book Dream of the Red Chamber in the Metaverse of Dream of the Red Chamber are limited, which inevitably leads to situations where people entering the Metaverse of Dream of the Red Chamber need to temporarily generate virtual avatars when choosing them, and

Figure 6. The Metaverse workflow of Dream of the Red Chamber.

Figure 7. Process schematic diagram of the virtual reality Metaverse of Dream of the Red Chamber.

they need to change certain characteristics of the generated characters to ensure their uniqueness. The general idea for dealing with this situation is to prepare a character in advance for cloning, which is wearing a code that can dynamically change during the operation of the Metaverse. When logging into the Metaverse, determine whether the character corresponding to the virtual avatar code of the login belongs to the character in Dream of the Red Chamber. If so, activate the character; if not, activate the backup clone object, clone it using the Instantiate function, and replace the headband encoding with the current virtual avatar encoding [6] .

2.1.2. Dynamically Loading External Materials

The ecology of the Metaverse of Dream of the Red Chamber is constantly changing, but these changing elements cannot be imported in advance, which requires dynamically loading from external sources. Unity3D provides corresponding methods (functions) for different element types (Table 1).

2.2. Integrating External Virtual Reality Elements in Unity3D

The virtual reality elements of the Metaverse of Dream of the Red Chamber still rely more on the Unity3D environment and are imported from outside through interactive operations. After importing, it is usually necessary to perform secondary editing on these elements. For example, redefining image accuracy, defining animation clips, and so on. Orderly place the imported elements into the scene, configure the lighting, and define the corresponding parameters of lighting/environment. In this way, the most basic work of virtual reality in the Metaverse of Dream of the Red Chamber is basically completed.

2.3. Control of Virtual Reality Elements in Unity3D

2.3.1. Control of Characters

Including the behavior of characters in the Metaverse of Dream of the Red Chamber, such as walking, running, speaking, etc., there are two main control methods used by Unity3D: One is to continuously change the position and angle of the character; the other way is to activate the animation attached to the character. There are generally two methods for implementing control: manual intervention and intelligent (AI) computing. The exact method used depends on the specific situation. For example, during the fair seasons in the Metaverse of Dream of the Red Chamber, it is very natural to use AI in social activities to find a target partner among the crowd. Usually, changes in subjective perspective are achieved through manual intervention [7] .

In Unity, there are multiple methods to achieve different types of character perspective control. These methods can be selected based on the activity needs in the Metaverse of Dream of the Red Chamber (Table 2).

2.3.2. Control of Non-Character-Type Elements

In the Metaverse of Dream of the Red Chamber, the non-character elements include all the elements outside the characters, such as the visible sceneries, props, equipment and devices that satisfy various somatic external connections, and the

Table 1. List of methods used for Unity3D dynamically loading of external elements.

Table 2. Unity3D’s method of controlling the character’s perspective in virtual reality.

various digital media (text, images, animation, video, audio) that are integrated into the Metaverse. The control of these elements is quite complex and flexible. Along with the iterative updating of related hardware and software technologies, the corresponding specific control methods will also be upgraded and improved (Table 3).

2.4. Satisfaction in Immersion and Diversity

The Metaverse of Dream of the Red Chamber is based on the content of literary works, with an artistic foundation that transcends reality, and therefore has an infinite space for imagination. However, this is not enough, there should also be a lot of freedom and diversity beyond reality. For example, spatial transfer, changes in perspective, diversity in the presentation style of interactive objects, and infinite related expansion of content [8] .

The immersion of the Metaverse of Dream of the Red Chamber includes two aspects: immersion and immersive experience. Starting from entering the Metaverse of Dream of the Red Chamber, everyone views the world from a subjective perspective (first person perspective), and is able to fully control their body and engage in various behaviors they want, just like being in the real world. This is the sense of substitution. In the real world, everyone is in a certain environment no matter when or where they are. Entering the Metaverse of Dream of the Red

Table 3. List of Unity3D’s control for the non-character-type elements in the Metaverse of Dream of the Red Chamber.

Chamber also requires this feeling: always being in the world depicted in Dream of the Red Chamber.

3. Realizing Free-Barrier Real-time Communication in the Metaverse of Dream of the Red Chamber

3.1. Socket.IO for Realization of Internet Connectivity

The Metaverse of Dream of the Red Chamber is usually an online digital environment, so a stable internet connection is needed to support user interaction.

Socket.IO is a popular cross platform real-time communication library used to achieve real-time connections in internet applications. It is built on WebSocket technology and provides high-level abstraction and convenient APIs for internet connectivity. After installing the Socket.IO library, you can create a Socket.IO server. In Node.js, use the Socket.IO library to create a server:

const io = require('')(server);

io.on('connection', (socket) => {

console.log('A user connected');

3.2. The Client Terminal of the Socket.IO Created by the Unity C# Script

Through Socket.IO for the Metaverse of Dream of the Red Chamber to prepare the network environment, but does not mean that you can immediately enter the network interaction state, but also need to in the Unity front-end application, the introduction of Socket.IO client library, in order to establish a connection with the Socket.IO server. After the successful connection, the Metaverse can really operate. Using C# as an example, the using Socket.IO Client directive provides access to Socket.IO client functionality, which can be used to establish a Socket.IO connection and communicate in real-time in C#. The library Socket.IO Client can help you establish a connection with the Socket.IO server and send or receive data [9] .

3.3. Unity + Socket.IO Connection for Realizing Interpersonal Communi Cation

When the Socket.IO client application starts, it attempts to connect to the Socket.IO server. After a successful connection, the client and server can send messages and events to each other.

// Send the message to the server

socket.emit(‘chat message’, ‘Hello, world! ‘);

// Listens for messages sent by the server

socket.on(‘chat message’, (message) => {

console.log(‘Received message: ‘ + message);


On both the client and server side, you can define message and event handlers to communicate over the connection. For example, you can define an event to handle the sending and receiving of a chat message (Figure 8).

The Metaverse of Dream of the Chamber is an attempt to provide a completely realistic experience world, and a very important guarantee for this realism is low latency, that is, the speed of data from the client to the server and back again. The better the network status, the faster the server response; The smaller the number of users, the lower the latency. In games that require quick reactions, such as competitive and RPG battles, latency has a significant impact on the game. Technically, it is possible to control the number of people, coordinate the execution of transactions, simplify the presentation of data, and reference efficient algorithms or programming ideas [10] .

4. The management of Digital Virtual Identity in the Metaverse

4.1. The Uniqueness Principle of Digital Virtual Identity Registration

When entering the Metaverse of Dream of the Red Chamber, everyone will

Figure 8. Unity3D + Socket.IO network communication schematic in the Metaverse.

receive a digital identity after successfully logging in, which corresponds to a digital code. This code is unique and scientifically and rationally designed. It not only follows the prevailing rules in the industry, but also meets the individual needs of the Metaverse itself. The code is composed of several intervals of legal characters, and each interval corresponds to a special meaning (attribute), such as the digital person’s occupation, gender, technical expertise, etc. As far as a single interval is concerned, most of them are not unique, but the final code formed after combination is unique. The encoding of digital identity is not freely chosen by those who enter the Metaverse, but is automatically completed by the Metaverse digital identity registration process. This processing is also to ensure the strict and orderly uniqueness of digital identity encoding. The principle of uniqueness of digital identity is crucial, and everyone who enters the Metaverse must strictly abide by it, because it is the prerequisite to ensure to orderly operate and manage the Metaverse (Figure 9).

4.2. The Login Authentication of Digital Identity and Digital Avatars Im plemented by Unity

Digital identity is a human attribute in the Metaverse and is concealed, so it requires a recognizable digital image, which is a digital avatar. A digital avatar is a digital person with unique characteristics. The digital human avatars in the Metaverse are characters mentioned in the book Dream of the Red Chamber or virtual characters exclusive to the Metaverse. However, the avatar is not necessarily exclusive to the identity corresponding to a certain identity code. In other

Figure 9. Registration UI of digital identity in the Metaverse.

words, although the virtual identity code in the Metaverse is unique and is generally fixed for the life entering the Metaverse, the image corresponding to this identity may be different from the last time someone entered the Metaverse. It is different, and the image (digital person) may have been used by someone else before. This is different from the one-to-one correspondence between each person’s identity code (ID card) and physical body in the real world. However, this does not prevent each digital person appearing in the Metaverse of Dream of the Red Chamber from maintaining unique characteristics. Although the difference sometimes seems small, there is actually a difference. Digital avatars (digital people) are the basis for creating a sense of life and a humanistic atmosphere in the Metaverse, and are therefore the first step in building a complete ecology of the Metaverse.

4.3. The Management of Identity Registration and Login for Digital Virtual Characters

The process of using the Unity + Socket.IO method to realize the Metaverse identity registration is: Unity completes the identity registration, and then Unity sends a request to save relevant information to the server-side Socket.IO. Socket.IO immediately saves the registration information in the corresponding data text (such as Json) on the server side after responding to the request. The purpose of login authentication in the Metaverse of Dream of the Red Chamber is to ensure the legality of the identity of the person entering. Only those who are legal can enter the Metaverse, which can provide relevant benefits and assign corresponding digital incarnations accordingly.

Following the above description on the implementation of the virtual identity registration function of the Metaverse. The client login operation is implemented by Unity. When the client operation is completed, a login information comparison request is sent to the server-side Socket.IO. After Socket.IO responds to the request; it immediately reads the registration information data text on the server side and compares the data. If the comparison is successful, the client enters the Metaverse; otherwise, a login error is displayed, and then the login UI is entered again (Figure 10).

Strict control of digital identity registration and login, such as avoiding duplication of registration information, input of illegal characters, etc., is a key technical guarantee and work link to ensure the uniqueness of digital identity.

4.4. The Management of Digital Identity Information in the Metaverse

The Metaverse of Dream of the Red Chamber realizes the management of virtual character identity information, including the addition, deletion, retrieval, summary, output and other aspects of related information. The addition of virtual identity is actually completed when the virtual identity is registered, and it is only listed and read in the information management UI, so other operations are

Figure 10. Login UI of the Metaverse of Dream of the Red Chamber.

implemented in the information management UI. The UI is opened in two cases: one is automatically opened in the Metaverse according to the statistical results of the registrant’s activity index (for example, it is found that a registrant’s activity index is lower than the specified minimum activity index), and the other is opened regularly or irregularly by the Metaverse manager because of management needs [9] .

Technically, the above-mentioned virtual identity information management UI and related information management operations are all implemented by Unity. The reading of the original information, the completion of editing (the information management operation is completed), and the saving of the latest information are jointly completed by Unity + Socket.IO: Unity sends a request to Socket.IO for asking to read the corresponding text (such as Json) of the registration information, and Socket.IO responds and feeds back relevant data to Unity. After receiving the data, Unity will present it in the UI through format conversion. After the management work is completed, Unity sends a request to Socket.IO to save information. After responding to, Socket.IO saves the latest information in the relevant text (directly overwriting the original text) (Figure 11).

5. Management and Maintenance of the Ecological Information of the Metaverse Civilization

Dream of the Red Chamber is an encyclopedia. The Metaverse constructed on this basis is an all-encompassing virtual world. Therefore, the management and

Figure 11. The Identity Management Process of Virtual Characters in the Metaverse of Dream of the Red Chamber by Unity + Socket.IO.

maintenance of civilized ecological information is a complex process involving many aspects, including data management, security, compliance, etc.

5.1. Data Management and Analysis

Establish an effective data management system, including collection, storage, processing and analysis of ecological information of the Metaverse of Dream of the Red Chamber. This can help monitor and evaluate the functioning of various parts of the Metaverse and support the decision-making process.

5.2. Security and Privacy Protection

Ensure data security in the Metaverse of Dream of the Red Chamber and take appropriate measures to protect users’ private information. This can include security measures such as encryption technology, access control and authentication.

5.3. Compliance and Supervision

Comply with relevant laws and regulations, including data protection laws and privacy regulations. Establish data management and processing procedures that comply with regulatory requirements to ensure compliance with legal requirements during the data management process.

5.4. Community Engagement and Communication

Establish good communication channels with the Metaverse community of Dream of the Red Chamber, understand their needs and feedback, and actively participate in community activities. This helps build trust and support and promotes a good community atmosphere and development.

5.5. Technological Innovation and Development

Actively adopt new technologies and solutions, including artificial intelligence, blockchain and big data analysis, to improve the efficiency and effectiveness of the ecological information management of the Metaverse of Dream of the Red Chamber.

5.6. Improve the Advance and Retreat Mechanism

Enabling social interaction requires real-time communication technology and user interface design and exit management. Among them, real-time communication is handled by Socket.IO, and the user interface is implemented using Unity. Entering the Metaverse of Dream of the Red Chamber is not restricted by location. Everyone can use the terminal to enter and exit the Metaverse anytime and anywhere. However, the Metaverse will not let people exit easily, and there will be strict exit management: when the client behaves to exit the Metaverse of Dream of the Red Chamber (essentially exiting the Unity UI), Unity sends exit information to Socket.IO, and Socket.IO immediately implements the mechanism for handling disconnection will be started, specific events will be triggered, and the aftermath of client exit will be completed: client online information update, virtual identity avatar hiding, etc. [11] .

Conflicts of Interest

The author declares no conflicts of interest regarding the publication of this paper.


[1] Li, H. (2020) Digital Review of Dream of the Red Chamber and Enlightenment of Blockchain. Dream of the Red Chamber, 3, 83-102.
[2] Zhang, J.Y. and Bu, Y.F. (2022) Construction of Meta-Universe Reading Scene from the Perspective of Availability. Publishing Angle, 18, 44-50.
[3] Xia, J.W. (2023) Features, Risks and Governance Principles of Meta-Universe. Search, 5, 68-73.
[4] Ji, D.Y. (2023) Features of Digital Twins and Their Relationship with the Meta-Universe. Robotics Technology and Application, 2, 7-11.
[5] Yuan, X.Q. (2023) Analysis of Three-Dimensional Image Space Narrative Features in the Context of Meta-Universe. Journal of Hunan University (Social Science Edition), 3, 80-87.
[6] Xie, X.L. (2023) Knowledge Sharing Behavior and Driving Factors of Academic Virtual Community under the Enabling of Meta-Universe. Library Work and Research, 10, 3-12.
[7] Huang, W., Xia, C.J. and Tie, Z. (2023) Digital Memory in the Meta-Universe: Digital Memory Value of “Virtual Digital Person”. Library Forum, 154-161.
[8] Wu, W.Y. and Wang, X. (2023) The Ethical Dilemma and Transcendence of Digital Identity Construction. Learning and Practice, 6, 30-38.
[9] He, Y. and Zhang, C.Y. (2020) Design and Implementation of Neurofeedback Intervention System Based on Unity. Computer Science, 47, 579-583.
[10] Chen, X.Q. (2016) Real-Time Communication between Server and Browser Based on Socket.IO Framework. Yangtze River Engineering: Journal of Changjiang Institute of Technology, 1, 31-32.
[11] Lin, L. (2023) Building a Dual Mechanism for Protecting Sensitive Personal Information in the Meta-Universe. Contemporary Communication, 2, 99-103.

Copyright © 2024 by authors and Scientific Research Publishing Inc.

Creative Commons License

This work and the related PDF file are licensed under a Creative Commons Attribution 4.0 International License.