Are the two services on the same local network?

2 years ago

The thing is, I'm using:

The default settings for server and client are as follows:
host: 127.0.0.1
port: 1025

But when I try to connect I get this error:

[08.07.2024 00:20:25] [ERROR] [views.py:129] :: [Errno 111] Connection refused

Also for client and server I set only secret_key from class parameters. As far as I understand, websocket is used for connection, I haven't worked with it yet, so I don't fully understand how everything works there. But when I run the site and discord bot from my computer with the same settings, everything works fine

9 Replies

2 years ago

not exactly a local network, they are a part of the same private network, so you just need to use the service's assigned private domain


2 years ago

Am I correct in assuming you mean any of these?

1259668894096953300


2 years ago

spherically the domain you censored, btw it's not sensitive information in the slightest


2 years ago

discord bot code:

import os

import discord
from discord import Intents
from discord.ext import commands

from discord.ext.ipc import Server
from discord.ext.ipc.objects import ClientPayload

HOST = os.getenv('HOST')
TOKEN = os.getenv('TOKEN')
SECRET = os.getenv('SECRET')

intents = Intents.default()
intents.message_content = True
intents.members = True


class NetrixBot(commands.Bot):
    def __init__(self):
        super().__init__(
            command_prefix='n!', intents=intents)

        self.ipc = Server(
            self, host=HOST, secret_key=SECRET)

    async def setup_hook(self) -> None:
        await self.ipc.start()

    async def on_ready(self):
        print(f'BOT: {self.user}')
        print(f'ID: {self.user.id}')
        print(f'API VERSION: {discord.__version__}')

    @Server.route()
    async def check_exist_guild(self, data: ClientPayload) -> dict:
        guild = self.get_guild(int(data.guild_id))
        if guild is None:
            return {'result': False}

        return {'result': True, 'member_count': guild.member_count}


if __name__ == '__main__':
    bot = NetrixBot()
    bot.run(token=TOKEN)

Current value:
HOST = 0.0.0.0

When I tried to enter:
netrix.railway.internal
I got:

[2024-07-08 00:44:18] [INFO    ] discord.client: logging in using static token
Traceback (most recent call last):
  File "/app/main.py", line 46, in 
    bot.run(token=TOKEN)
  File "/opt/venv/lib/python3.11/site-packages/discord/client.py", line 869, in run
    asyncio.run(runner())
  File "/root/.nix-profile/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/root/.nix-profile/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.nix-profile/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/discord/client.py", line 858, in runner
    await self.start(token, reconnect=reconnect)
  File "/opt/venv/lib/python3.11/site-packages/discord/client.py", line 786, in start
    await self.login(token)
  File "/opt/venv/lib/python3.11/site-packages/discord/client.py", line 629, in login
    await self.setup_hook()
  File "/app/main.py", line 28, in setup_hook
    await self.ipc.start()
  File "/opt/venv/lib/python3.11/site-packages/discord/ext/ipc/server.py", line 219, in start
    await self.create_server("standard", self.standard_port, self.standart_handler)
  File "/opt/venv/lib/python3.11/site-packages/discord/ext/ipc/server.py", line 180, in create_server
    self.servers[name] = await serve(ws_handler, self.host, port)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/websockets/legacy/server.py", line 1116, in __await_impl__
    server = await self._create_server()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/.nix-profile/lib/python3.11/asyncio/base_events.py", line 1539, in create_server
    raise OSError('could not bind on any address out of %r'
OSError: could not bind on any address out of [('fd12:5421:b921::a1:1d06:3971', 1025, 0, 0)]

For the client, I have HOST set up:
netrix.railway.internal

1259673912720097300


2 years ago

you can't bind to a domain, you need to bind to :: but use the domain when you connect to the service


2 years ago

Basically I specified in the HOST for the client:
netrixfun.railway.internal from the Private Networking bot

For the bot as HOST as you said ::
and it worked. But I have one more question, if I replace :: with - netrixfun.railway.internal will it still work?

1259678456040521700
1259678456430723000
1259678456745300000
1259678456988434400


2 years ago

It is still better to leave ::, with other values nothing works


2 years ago

@Brody Thank you for your help <:salute:1137099685417451530>


2 years ago

yes :: is what you want to use to listen on


Loading...