I’m trying to deploy the simplest python app ever to receive UDP messages. simply.py
looks like this:
import socket
print("Hello Fly.io!")
UDP_IP = "fly-global-services"
UDP_PORT = 5000
sock = socket.socket(socket.AF_INET,
socket.SOCK_DGRAM)
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print("received message: %s" % data)
the fly.toml
looks like this
# fly.toml file generated for hellopython on 2022-04-15T04:05:30+01:00
app = "hellopython"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
[env]
PORT = "5000"
[experimental]
allowed_public_ports = []
auto_rollback = true
[[services]]
internal_port = 5000
processes = ["app"]
protocol = "udp"
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
port = "5000"
[[statics]]
guest_path = "/app/public"
url_prefix = "/static/"
the Dockerfile
file:
ARG PYTHON_VERSION=3.7
FROM python:${PYTHON_VERSION}
RUN apt-get update && apt-get install -y \
python3-pip \
python3-venv \
python3-dev \
python3-setuptools \
python3-wheel
RUN mkdir -p /app
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
# replace APP_NAME with module name
CMD ["python", "simply.py"]
and the Procfile:
web: python simply.py
No matter what I do, I always get an error (on the logs) like this:
2022-04-15T03:16:30.769 runner[ab129be9] lhr [info] Starting virtual machine
2022-04-15T03:16:31.189 app[ab129be9] lhr [info] Starting init (commit: 252b7bd)...
2022-04-15T03:16:31.189 app[ab129be9] lhr [info] Preparing to run: `python simply.py` as root
2022-04-15T03:16:31.190 app[ab129be9] lhr [info] 2022/04/15 03:16:31 listening on [fdaa:0:5a7f:a7b:276d:ab12:9be9:2]:22 (DNS: [fdaa::3]:53)
2022-04-15T03:16:56.515 runner[b2f6e65b] lhr [info] Shutting down virtual machine
2022-04-15T03:16:56.851 app[b2f6e65b] lhr [info] Sending signal SIGINT to main child process w/ PID 515
2022-04-15T03:16:56.854 app[b2f6e65b] lhr [info] Traceback (most recent call last):
2022-04-15T03:16:56.854 app[b2f6e65b] lhr [info] File "simply2.py", line 14, in
2022-04-15T03:16:56.854 app[b2f6e65b] lhr [info] data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
2022-04-15T03:16:56.854 app[b2f6e65b] lhr [info] KeyboardInterrupt
2022-04-15T03:16:56.854 app[b2f6e65b] lhr [info] Hello Fly.io!
2022-04-15T03:16:57.856 app[b2f6e65b] lhr [info] Main child exited normally with code: 1
2022-04-15T03:16:57.857 app[b2f6e65b] lhr [info] Starting clean up.
Can someone please explain to me what I am doing wrong, and how can I make this work?
I’m pretty lost here. Any help will be greatly appreciated.
Thank you