Simple chat room case

I. Design of chat room data transmission

This is a case of people chatting composed, so called chat rooms.

Its basic element is the multiple clients, servers.

Requirements: client, server

Constraints necessary: ​​data transmission protocol (in this case, each row is a data)

Principle: The server listens sources, connect to the server and the client sends a message to the server

 

Second, the client, server data exchange

The client sends a request to the server, the server receives the message, the client send a return message.

This process can be devices on the LAN, the device can be on the Internet.

 

Third, the data transmission protocol

Data to be transmitted (in the string "Hello", for example) converted to a length byte array 5, followed by a newline additional transcoding, byte array length becomes 6.

So this case, real transmission is 6 bytes.

When the other client or server receives a message, the message traverse, if newline obtained, then data is a whole, then extract information before a new line.

 

Fourth, the client server model

The client has a pc, mobile phone, tablet and other devices that can transmit information to the server.

For example, PC sends a message to the server, the server receives the message, such as mobile phones and tablet send messages to other connected client. Mobile phones and flat-panel received the message after the process to achieve the pc and mobile phones, tablet interaction.

So, pc and mobile phones to communicate, not send messages directly, unless there between pc or mobile phone is a server, a client. However, in the case of both of which are clients, not information transmission. Unless you are using udp broadcast mode. But the broadcast, since the message is very large, will lead to congestion in the network.

 

Fifth, client-server network model

If you want to send a message to other devices, these devices are the client, and not in the same local area network. Well, this time the server needs to be deployed outside the inter-line network.

All devices connected to the server through the route, when pc to communicate with other devices, firstly sends a message to the server, the server parsing, forwarding data to other devices connected to the server.

Published 174 original articles · won praise 115 · views 830 000 +

Guess you like

Origin blog.csdn.net/nicolelili1/article/details/103978878