-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Description
Today I discovered a very strange issue, the UDP/8000 port is not accessible. There are no issues with the security group and listener, but after tinkering for a while, I had to raise a ticket with the cloud service provider for further investigation.
During the process of raising the ticket, I realized that troubleshooting the accessibility of UDP ports is a more complicated issue compared to checking if TCP port 22 is accessible. Unlike TCP, there is no commonly used UDP server to test the connectivity, making it difficult to investigate.
In the end, it was discovered that the UDP ports below 8000 were blocked by the company. There were no issues when using 4G or home WiFi, but changing to UDP port 18000 resolved the problem. This indicates that:
- WebRTC: Support listen at multiple UDP ports. #2848
- WebRTC: WebRTC over TCP directly, not TURN, TCP transmission (non-TURN) #2852
I found some simple UDP servers and clients that can be run on my own server, and then tested them on the client side.
OBS WHIP
NC
Start a UDP server:
nc -l -k -u 8000Start a UDP client:
echo 'Hello' |nc -u 127.0.0.1 8000If success, you should see the message in the UDP server.
IPERF
Start a UDP server:
iperf -s -u -p 8000Start a UDP client:
iperf -c 127.0.0.1 -u -b 10g -p 8000If success, you can see the report of bandwidth.
Go
Code snippet: Gist
Start the server:
go run server.go
Execute the command to check if the listening is normal:
netstat -lnptu | grep 8000
# udp 0 0 0.0.0.0:8000 0.0.0.0:* 1016220/server
Execute the nc command, send the message Hello to the server, and then press Enter:
nc -u 127.0.0.1 8000
# Hello
# Pong: Hello
Run the client on the local machine:
go run client.go
The result should be normal:
Ping: Hello, UDP server
Pong: Hello, UDP serverRun the client, specifying the remote server:
go run client.go 101.20.7.11
Below is the code to prevent everyone from accessing the gist. Other languages are welcome to contribute.
server.go
/*
Usage:
go run server.go
See https://gist.github.com/winlinvip/e8665ba888e2fd489ccd5a449fadfa73
See https://stackoverflow.com/a/70576851/17679565
*/
package main
import (
"fmt"
"net"
"os"
"strconv"
)
func main() {
serverPort := 8000
if len(os.Args) > 1 {
if v,err := strconv.Atoi(os.Args[1]); err != nil {
fmt.Printf("Invalid port %v, err %v", os.Args[1], err)
os.Exit(-1)
} else {
serverPort = v
}
}
addr := net.UDPAddr{
Port: serverPort,
IP: net.ParseIP("0.0.0.0"),
}
server, err := net.ListenUDP("udp", &addr)
if err != nil {
fmt.Printf("Listen err %v\n", err)
os.Exit(-1)
}
fmt.Printf("Listen at %v\n", addr.String())
for {
p := make([]byte, 1024)
nn, raddr, err := server.ReadFromUDP(p)
if err != nil {
fmt.Printf("Read err %v", err)
continue
}
msg := p[:nn]
fmt.Printf("Received %v %s\n", raddr, msg)
go func(conn *net.UDPConn, raddr *net.UDPAddr, msg []byte) {
_, err := conn.WriteToUDP([]byte(fmt.Sprintf("Pong: %s", msg)), raddr)
if err != nil {
fmt.Printf("Response err %v", err)
}
}(server, raddr, msg)
}
}clieng.go
/*
Usage:
go run client.go
go run client.go 101.201.77.240
See https://gist.github.com/winlinvip/e8665ba888e2fd489ccd5a449fadfa73
See https://stackoverflow.com/a/70576851/17679565
*/
package main
import (
"fmt"
"net"
"os"
"strings"
)
func main() {
serverEP := "127.0.0.1"
if len(os.Args) > 1 {
serverEP = os.Args[1]
}
if !strings.Contains(serverEP, ":") {
serverEP = fmt.Sprintf("%v:8000", serverEP)
}
conn, err := net.Dial("udp", serverEP)
if err != nil {
fmt.Printf("Dial err %v", err)
os.Exit(-1)
}
defer conn.Close()
msg := "Hello, UDP server"
fmt.Printf("Ping: %v\n", msg)
if _, err = conn.Write([]byte(msg)); err != nil {
fmt.Printf("Write err %v", err)
os.Exit(-1)
}
p := make([]byte, 1024)
nn, err := conn.Read(p)
if err != nil {
fmt.Printf("Read err %v\n", err)
os.Exit(-1)
}
fmt.Printf("%v\n", string(p[:nn]))
}
TRANS_BY_GPT3