Skip to content

WebRTC: A small tool for testing UDP connectivity on UDP 8000. #2843

@winlinvip

Description

@winlinvip
Member

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:

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

See English or Chinese

NC

Start a UDP server:

nc -l -k -u 8000

Start a UDP client:

echo 'Hello' |nc -u 127.0.0.1 8000

If success, you should see the message in the UDP server.

IPERF

Start a UDP server:

iperf -s -u -p 8000

Start a UDP client:

iperf -c 127.0.0.1 -u -b 10g -p 8000

If 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 server

Run 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

Activity

added this to the 5.0 milestone on Jan 4, 2022
self-assigned this
on Jan 4, 2022
changed the title [-]WebRTC: UDP/8000 check tool for WebRTC 检测UDP/8000是否可以访问的工具[/-] [+]WebRTC: UDP/8000 check tool 检测UDP/8000是否可以访问的工具[/+] on Jan 4, 2022
fandong1993

fandong1993 commented on Jan 22, 2022

@fandong1993

Hello, author,

I have also confirmed that it is an issue with the upd8000 port. I would like to ask how you modified the udp port. I changed the host port to 18000, but the container's port remained as 8000. As a result, the rtc cannot play properly, and the playback address, whether it is webrtc://host/live/livestream or webrtc://host:18000/live/livestream, keeps spinning.

Thank you.

TRANS_BY_GPT3

winlinvip

winlinvip commented on Jan 23, 2022

@winlinvip
MemberAuthor

Currently, the host's port and the container's port are not supported to be different. You need to change the listening port of the container as well. Please refer to the WIKI for specific instructions.

TRANS_BY_GPT3

fandong1993

fandong1993 commented on Jan 23, 2022

@fandong1993

Hmm, I understand now. The ones inside the container also need to be modified...
Just as I opened my computer, I suddenly saw your reply. Thank you.

Wishing you a happy new year in advance.

TRANS_BY_GPT3

changed the title [-]WebRTC: UDP/8000 check tool 检测UDP/8000是否可以访问的工具[/-] [+]WebRTC: UDP/8000 check tool' is a tool used to check whether UDP/8000 can be accessed.[/+] on Jul 28, 2023
changed the title [-]WebRTC: UDP/8000 check tool' is a tool used to check whether UDP/8000 can be accessed.[/-] [+]WebRTC: A small tool for testing WebRTC UDP connectivity on port 8000.[/+] on Sep 18, 2023
changed the title [-]WebRTC: A small tool for testing WebRTC UDP connectivity on port 8000.[/-] [+]WebRTC: A small tool for testing UDP connectivity on UDP 8000.[/+] on Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

DiscussionDiscussion or questions.TransByAITranslated by AI/GPT.WebRTCWebRTC, RTC2RTMP or RTMP2RTC.

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @winlinvip@fandong1993

      Issue actions

        WebRTC: A small tool for testing UDP connectivity on UDP 8000. · Issue #2843 · ossrs/srs