Question

Cannot deploy a ruby udp server and open port on ubuntu droplet

Hi. I have a working ruby 2.7.2 app that is a simple udp server on my local development machine which uses the ruby UDPSocket library. I have created a ubuntu 18.04 droplet and created a cloud firewall with a custom inbound rule protocol:udp, port range:7373. I have created a non-sudo user (m32_udp) and placed the app in /var/www/m32_udp/code directory with these privilages.

m32_udp@megazoic:/var/www/m32_udp/code$ ls -l total 24 -rw-r–r-- 1 m32_udp m32_udp 60 Nov 11 22:56 Gemfile -rw-r–r-- 1 m32_udp m32_udp 100 Nov 11 23:51 Gemfile.lock -rw-r–r-- 1 m32_udp m32_udp 368 Nov 11 22:56 client.rb -rw------- 1 m32_udp m32_udp 115 Nov 12 01:14 nohup.out -rw-r–r-- 1 m32_udp m32_udp 2194 Nov 11 22:56 server.rb

My ruby code (abbreviated) is

    @socket = UDPSocket.new
    @socket.bind("0.0.0.0", @port)

I have also tried entering my droplet’s ip address in the bind parameter. Also @port is 7373.

When I start the app as m32_udp user, netstat reports…

watchdog@megazoic:~$ netstat -an Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 192.241.196.39:22 97.115.135.18:59072 ESTABLISHED tcp 0 316 192.241.196.39:22 97.115.135.18:59064 ESTABLISHED tcp6 0 0 :::22 :::* LISTEN
udp 0 0 127.0.0.53:53 0.0.0.0:*
udp 0 0 0.0.0.0:7373 0.0.0.0:*

When I change the ruby code in my app to

@socket.bind("192.241.196.39")

netstat reports
udp 0 0 192.241.196.39:7373 0.0.0.0:*

In either case, I cannot see this port as being open using netcat from another machine. It is also not reported as LISTEN in netstat. Do I need to run this app with sudo privileges? Do I have the ip address correct in the bind statement? Thanks for any help that you can provide!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

My bad. This was working with the original socket.bind call using 0.0.0.0

I guess that I expected netstat to report LISTEN for this port as my app was indeed listening.

Thanks for looking

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.