Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

40 lines of code chat room

2025-02-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

I saw a great timely communication project today and shared it with you.

Server: lhttp

40 lines of code chat room: demo

Basically, you don't have to write a single line of code on the server side of a chat room, but a very small amount of code on the client side.

It is worth mentioning that the author's idea is very good, the communication protocol is a bit similar to the http protocol, so the scalability is better, the entire server can be easily customized, the author implements and some very important first filters, such as subscription and publication.

If the http protocol is to locate resources, then the greatest use of lhttp is to transmit commands. Is based on the websocket protocol.

What I like most is subscription and publishing, such as:

Send a string like this via websocket:

"LHTTP/1.0 command\ r\ nsubscribe:channel_test\ r\ n\ r\ n"

This means that the link subscribes to the channel_test channel. Suppose another client sends such a string:

"LHTTP/1.0 command\ r\ npublish:channel_test\ r\ n\ r\ nhello"

In this way, all subscribers can receive this message, and the message body is hello.

The command here is very similar to http's url, and the server can register the processor to process this command according to the command. The client can also be handled similarly, such as the command can be chat (chat) enter_group (join the discussion group) add_friend (add friends) and so on, which is very flexible.

Also support some agents and other features, I will not say more, everyone to study and learn together, there is an exchange group: 171358414

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report