Running a UDP Server on WSL Ubuntu and Accessing it from Windows Side Wi-Fi Hotspot
Windows Subsystem for Linux (WSL) is a compatibility layer for running Linux binary executables natively on Windows 10. Ubuntu is one of the most popular Linux distributions available on WSL. In this article, we will discuss how to run a UDP server on WSL Ubuntu and access it from the Windows side Wi-Fi hotspot.
Prerequisites
Before we begin, make sure you have the following:
- Windows 10 with WSL and Ubuntu installed
- A Wi-Fi hotspot enabled on your Windows machine
Setting up the UDP Server on WSL Ubuntu
We will use the xinetd service to manage our UDP server. To install it, run the following commands on your WSL Ubuntu terminal:
sudo apt update
sudo apt install xinetdNext, create a new file named /etc/xinetd.d/udp-server and add the following content:
service udp-server
{
socket_type = stream
protocol = udp
wait = no
user = root
server = /usr/bin/nc
server_args = -u -l 1234
disable = no
}This configuration sets up a UDP server that listens on port 1234. You can change the port number to your desired value.
Accessing the UDP Server from Windows
To access the UDP server from the Windows side, you need to find the IP address of your WSL Ubuntu instance. Run the following command on your WSL Ubuntu terminal to get the IP address:
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'Make a note of the IP address. Next, open the Windows Command Prompt and run the following command to test the connection:
nc -u 1234 Replace with the IP address of your WSL Ubuntu instance. If the connection is successful, you should see a message saying "Hello, World!" or whatever message you set up in your UDP server.
Creating a Wi-Fi Hotspot on Windows and Accessing the UDP Server
To create a Wi-Fi hotspot on Windows, go to the Windows Settings app, click on "Network & Internet," then "Mobile hotspot." Enable the hotspot and make a note of the network name and password.
Connect your device to the Wi-Fi hotspot and try accessing the UDP server using the same command as before:
nc -u 1234 Replace with the IP address of your WSL Ubuntu instance. If everything is set up correctly, you should be able to access the UDP server from your device.
- Install and configure the
xinetdservice on WSL Ubuntu - Set up a UDP server and listen on a specific port
- Find the IP address of your WSL Ubuntu instance
- Test the connection from Windows Command Prompt
- Create a Wi-Fi hotspot on Windows and connect your device
- Access the UDP server from your device