## 服务端配置 ``` [common] bind_port = 7000 vhost_http_port = 8007 subdomain_host = frp.tinywan.top ``` ## 客户端配置 ``` [websocket] type = http local_ip = 127.0.0.1 local_port = 7272 subdomain = websocket ``` ## Nginx 代理配置 ``` server { server_name websocket.frp.tinywan.top; location / { proxy_pass http://0.0.0.0:8007; #Proxy Settings proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header X-Real-IP $remote_addr; } } ``` > proxy_local_8007-websocket.frp.tinywan.top.conf ## WebSocket 测试 ``` ws = new WebSocket("ws://websocket.frp.tinywan.top:8007/"); ws.onopen = function() { console.log("连接成功"); ws.send('Tinywan'); console.log("给服务端发送一个字符串:Tinywan"); }; ws.onmessage = function(e) { console.log("收到服务端的消息:" + e.data); }; ``` ## 测试结果 ![](http://tinywan-develop.oss-cn-hangzhou.aliyuncs.com/18-8-25/48066424.jpg) ## 使用抓包工具看看 ```bash $ tcpdump -Ans 4096 -iany port 8007 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on any, link-type LINUX_SLL (Linux cooked), capture size 4096 bytes 16:30:04.788274 IP 122.233.225.125.56568 > 172.19.230.35.8007: Flags [P.], seq 1550440708:1550440855, ack 2093576114, win 254, length 147 E....4@.s..Vz..}...#...G\i..|.o.P.... .......zBOwX66|.`u. #6.V`=c./.hXxm@Jtx;M`c..1*~3&m6Hsv:Csz X7<i...a.`u..+!u.#!.V`;c.'!.@`~8Ipv>ItvmJ{.8.v{4Cv~n.{|4.$,=Iqm X! b.'!xXxmX.,6{.,oD..#cX? 16:30:04.804872 IP 172.19.230.35.8007 > 122.233.225.125.55695: Flags [P.], seq 2445804864:2445805007, ack 3725127516, win 60, length 143 E...."@.@......#z..}.G.....@...\P..<.G...~..{"type":"say","roomId":"L06777","userId":2196915,"userName":"Tinywan2196915","content":"Tinywan Hello","commentTime":"2018-08-25 08:30:06"} 16:30:04.805009 IP 172.19.230.35.8007 > 122.233.225.125.56568: Flags [P.], seq 1:144, ack 147, win 62, length 143 E...9^@.@..E...#z..}.G..|.o.\i..P..>.G...~..{"type":"say","roomId":"L06777","userId":2196915,"userName":"Tinywan2196915","content":"Tinywan Hello","commentTime":"2018-08-25 08:30:06"} 16:30:04.856772 IP 122.233.225.125.56568 > 172.19.230.35.8007: Flags [.], ack 144, win 254, length 0 E..(.;@.s...z..}...#...G\i..|.pAP....... 16:30:04.856868 IP 122.233.225.125.55695 > 172.19.230.35.8007: Flags [.], ack 143, win 259, length 0 E..(.<@.s...z..}...#...G...\....P...b_.. ``` [网络抓包更多](http://doc.workerman.net/debug/tcpdump.html)