lhttp alternatives and similar packages
Based on the "Networking" category.
Alternatively, view lhttp alternatives based on common mentions on social networks and blogs.
-
fasthttp
Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http -
kcptun
A Stable & Secure Tunnel based on KCP with N:M multiplexing and FEC. Available for ARM, MIPS, 386 and AMD64。N:M 多重化と FEC を備えた KCP に基づく安定した安全なトンネル。 N:M 다중화 및 FEC를 사용하는 KCP 기반의 안정적이고 안전한 터널입니다. Un tunnel stable et sécurisé basé sur KCP avec multiplexage N:M et FEC. -
gnet
🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go./ gnet 是一个高性能、轻量级、非阻塞的事件驱动 Go 网络框架。 -
Netmaker
Netmaker makes networks with WireGuard. Netmaker automates fast, secure, and distributed virtual networks. -
kcp-go
A Crypto-Secure, Production-Grade Reliable-UDP Library for golang with FEC -
netpoll
A high-performance non-blocking I/O networking framework, which focused on RPC scenarios, developed by ByteDance. -
fortio
Fortio load testing library, command line tool, advanced echo server and web UI in go (golang). Allows to specify a set query-per-second load and record latency histograms and other useful stats. -
mqttPaho
The Paho Go Client provides an MQTT client library for connection to MQTT brokers via TCP, TLS or WebSockets. -
go-getter
Package for downloading things from a string URL using a variety of protocols. -
gev
🚀Gev is a lightweight, fast non-blocking TCP network library / websocket server based on Reactor mode. Support custom protocols to quickly and easily build high-performance servers. -
nbio
Pure Go 1000k+ connections solution, support tls/http1.x/websocket and basically compatible with net/http, with high-performance and low memory cost, non-blocking, event-driven, easy-to-use. -
gmqtt
Gmqtt is a flexible, high-performance MQTT broker library that fully implements the MQTT protocol V3.x and V5 in golang -
easytcp
:sparkles: :rocket: EasyTCP is a light-weight TCP framework written in Go (Golang), built with message router. EasyTCP helps you build a TCP server easily fast and less painful. -
peerdiscovery
Pure-Go library for cross-platform local peer discovery using UDP multicast :woman: :repeat: :woman: -
gaio
High performance async-io(proactor) networking for Golang。golangのための高性能非同期io(proactor)ネットワーキング -
raw
Package raw enables reading and writing data at the device driver level for a network interface. MIT Licensed. -
winrm
Command-line tool and library for Windows remote command execution in Go -
arp
Package arp implements the ARP protocol, as described in RFC 826. MIT Licensed. -
go-cleanhttp
Get easily stdlib HTTP client, which does not share any state with other clients. -
ethernet
Package ethernet implements marshaling and unmarshaling of IEEE 802.3 Ethernet II frames and IEEE 802.1Q VLAN tags. MIT Licensed. -
buffstreams
A library to simplify writing applications using TCP sockets to stream protobuff messages
Static code analysis for 29 languages.
Do you think we are missing an alternative of lhttp or a related project?
Popular Comparisons
README
Your star is my power!! :rocket: :star: :star: :star: :star: :star:
Discribe
lhttp is a http like protocol using websocket to provide long live, build your IM service quickly scalable without XMPP!
Everything is customizable.
简体中文
Features
- simple easy but powerful!
- fast, publish 10000 messages using 0.04s(single-core CPU,1G memory).
- support cluster.
- easy to customize and expansion.
- work well with HTTP. So LHTTP can work with others language like PHP java python etc,.
A simple chat room demo
with lhttp javascript sdk we complete a simple chat room within 40 lines code!!
SDKs
- [x] javascript SDK webapp or website.
- [ ] c SDK ARM application or some c/c++ application.
Header filter development
Protocol stack:
+--------------------+
| lhttp |
+--------------------+
| websocket |
+--------------------+
| TCP |
+--------------------+
Architecture
+---------------------------------------+
| message center cluster (gnatsd) |
+---------------------------------------+
........|.................|...............|..................
| +-------------+ +-------------+ +-------------+ |
| |lhttp server | |lhttp server | |lhttp server | ... | lhttp server cluster
| +-------------+ +-------------+ +-------------+ |
.....|..........._____| |___.............| |_________......
| | | | | <----using websocket link
+--------+ +--------+ +--------+ +--------+ +--------+
| client | | client | | client | | client | | client |
+--------+ +--------+ +--------+ +--------+ +--------+
Quick start
go get github.com/nats-io/nats
go get github.com/fanux/lhttp
We need run gnatsd first:
cd bin
./gnatsd &
./lhttpd
Open anohter bash run lhttpClient, then input your command:
cd bin
./lhttpClient
Ship on docker
$ docker build -t lhttp:latest .
$ docker run -p 9090:9090 -p 8081:8081 lhttp:latest
Open two windows in your browser, enter http://localhost:9090
.
Lhttp server port is 8081, your own websocket client can connect to ws://localhost:8081
Enjoy the chat...
Alternative, pull image from docker hub.
$ docker run -p 9090:9090 -p 8081:8081 fanux/lhttp:latest
Protocol
LHTTP/1.0 Command\r\n --------start line, define command, and protocol [protocol/version] [command]\r\n
Header1:value\r\n --------headers
Header2:value\r\n
\r\n
body --------message body
for example:
LHTTP/1.0 chat\r\n
content-type:json\r\n
publish:channel_jack\r\n
\r\n
{
to:jack,
from:mike,
message:hello jack,
time:1990-1210 5:30:48
}
Usage
define your processor, you need combine
BaseProcessor
type ChatProcessor struct {
*lhttp.BaseProcessor
}
if you don't like BaseProcessor
, define your struct witch must has OnOpen(*WsHandler)
OnClose(*WsHandler)
method
like this:(don't recommand)
type ChatProcessor struct {
}
func (p ChatProcessor)OnOpen(h *WsHandler) {
//your logic
}
func (p ChatProcessor)OnClose(h *WsHandler) {
//your logic
}
func (p ChatProcessor)OnMessage(h *WsHandler) {
//your logic
}
regist your processor
lhttp.Regist("chat",&ChatProcessor{&lhttp.BaseProcessor{}})
then if command is "chat" ChatProcessor will handle it
define your onmessage handle
func (p *ChatProcessor)OnMessage(h *WsHandler) {
h.Send(h.GetBody())
}
Start websocket server
http.Handler("/echo",lhttp.Handler(lhttp.StartServer))
http.ListenAndServe(":8081")
Example , echo
type ChatProcessor struct {
*lhttp.BaseProcessor
}
func (p *ChatProcessor) OnMessage (h *lhttp.WsHandler) {
log.Print("on message :", h.GetBody())
h.Send(h.GetBody())
}
func main(){
lhttp.Regist("chat", &ChatProcessor{&lhttp.BaseProcessor{}})
http.Handle("/echo",lhttp.Handler(lhttp.StartServer))
http.ListenAndServe(":8081",nil)
}
Test
open websocketServer and run:
cd websocketServer
go run test.go
as we can see, both of the new headers are added and new command is set by the server. If we don't set a header or command ,then they will return the same result as they requested.
open an other bash, and run client in websocketClient
cd websocketClient
go run test.go
Subscribe/Publish
client1:
LHTTP/1.0 command\r\n
subscribe:channelID\r\n
\r\n
body optional
client2:
LHTTP/1.0 command\r\n
publish:channelID\r\n
\r\n
body require
client1:
LHTTP/1.0 command\r\n
unsubscribe:channelID\r\n
\r\n
body optional
client2 publish a message by channelID, client1 subscribe it, so client 1 will receive the message. if client1 send unsubscribe channelID, he will not receive message any more in channelID
support multiple channelID:
LHTTP/1.0 chat\r\n
subscribe:channelID1 channelID2 channelID3\r\n
\r\n
Using HTTP publish message!
lhttp support publish message by standard HTTP. URL: /publish . method: POST . body: use lhttp publishes message as HTTP body. for example I want send a message to who subscribe channel_test by HTTP.
resp,err := http.POST("https://www.yourserver.com/publish", "text/plain",
"LHTTP/1.0 chat\r\npublish:channel_test\r\n\r\nhello channel_test guys!")
when lhttp server receive this message, will publish whole body to channel_test.
your can use Publish
function in tools.go
//func Publish(channelID []string, command string, header map[string]string, body string) (err error) {
//}
//send message to who subscribe mike.
Publish("mike", "yourCommand", nil, "hello mike!")
Upstream
we can use lhttp as a proxy:
LHTTP/1.0 command\r\n
upstream:POST http://www.xxx.com\r\n
\r\n
body
lhttp will use hole message as http body, post to http://www.xxx.com if method is GET, lhttp send http GET request ignore lhttp message body:
LHTTP/1.0 command\r\n
upstream:GET http://www.xxx.com?user=user_a&age=26\r\n
\r\n
body
This case will show you about upstream proxy:
jack use lhttp chat with mike, lhttp is third part module, we can't modify lhttp server but we want to save the chat record, how can we do?
+----+ +----+
|jack| |mike|
+----+ +----+
|_____________ _______|
| |
+------------+
|lhttp server|
+------------+
|(http request with chat record)
V
+------------+
| http server| upstream server(http://www.xxx.com/record)
+------------+
(save chat record)
jack:
MESSAGE_UPSTREAM
LHTTP/1.0 chat\r\n
upstream:POST http://www.xxx.com/record\r\n
publish:channel_mike\r\n
\r\n
hello mike,I am jack
mike:
LHTTP/1.0 chat\r\n
subscribe:channel_mike\r\n
\r\n
when jack send publish message, not only mike will receive the message, the http server will
also receive it. witch http body is:MESSAGE_UPSTREAM
, so http server can do anything about
message include save the record
Multipart data
for example a file upload message, the multipart header record the offset of each data part, each part can have it own headers
LHTTP/1.0 upload\r\n
multipart:0 56\r\n
\r\n
content-type:text/json\r\n
\r\n
{filename:file.txt,fileLen:5}
content-type:text/plain\r\n
\r\n
hello
content-type:text/json\r\n\r\n{filename:file.txt,fileLen:5}content-type:text/plain\r\n\r\nhello
^ ^
|<---------------------first part------------------------->|<---------second part------------>|
0 56
why not boundary but use offset? if use boundary lhttp need ergodic hole message, that behaviour is poor efficiency. instead we use offset to cut message
How to get multipart data
for example this is client message.
LHTTP/1.0 upload\r\nmultipart:0 14\r\n\r\nk1:v1\r\n\r\nbody1k2:v2\r\n\r\nbody2
server code:
type UploadProcessor struct {
*lhttp.BaseProcessor
}
func (*UploadProcessor) OnMessage(ws *lhttp.WsHandler) {
for m := ws.GetMultipart(); m != nil; m = m.GetNext() {
log.Print("multibody:", m.GetBody(), " headers:", m.GetHeaders())
}
}
//don't forget to regist your command processor
lhttp.Regist("upload", &UploadProcessor{&lhttp.BaseProcessor{}})
Partners
*Note that all licence references and agreements mentioned in the lhttp README section above
are relevant to that project's source code only.