Skip to content

Questions about self-hosting a TW cloud server #648

Closed

Description

@JloAu

I wanted to host a TW cloud server on my computer and access it from another computer, but I didn't find how to.

Firstly, I set the server IP to my local IP address to try to access it from my local network: I don't get any error, but I can't connect the scratch project to the server (I set the same IP:port as the server in the URL), either on a computer on the local network or on the computer hosting the server...

I also tried with my external IP address (as a server IP) and by configuring port forwarding to the local IP address of the computer hosting the server: this time I get the following error:

Traceback (most recent call last):
  File "/mnt/0CB604AD0CB604AD/Téléchargements/Scratchattach.py", line 53, in <module>
    server = sa.init_cloud_server( server_ip, server_port, length_limit=None, allow_non_numeric=True, whitelisted_projects=None, allow_nonscratch_names=True, blocked_ips=[], sync_players=True, log_var_sets=False)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jloau/.venv/lib/python3.12/site-packages/scratchattach/eventhandlers/cloud_server.py", line 371, in init_cloud_server
    return TwCloudServer(
           ^^^^^^^^^^^^^^
  File "/home/jloau/.venv/lib/python3.12/site-packages/scratchattach/eventhandlers/cloud_server.py", line 202, in __init__
    SimpleWebSocketServer.__init__(self, hostname, port=port, websocketclass=websocketclass)
  File "/home/jloau/.venv/lib/python3.12/site-packages/SimpleWebSocketServer/SimpleWebSocketServer.py", line 622, in __init__
    self.serversocket.bind(hostInfo[0][4])
OSError: [Errno 99] Cannot assign requested address
Exception ignored in: <function BaseEventHandler.__del__ at 0x7df1baed3060>
Traceback (most recent call last):
  File "/home/jloau/.venv/lib/python3.12/site-packages/scratchattach/eventhandlers/_base.py", line 74, in __del__
    self.stop()
  File "/home/jloau/.venv/lib/python3.12/site-packages/scratchattach/eventhandlers/cloud_server.py", line 347, in stop
    BaseEventHandler.stop(self, wait_call_threads)
  File "/home/jloau/.venv/lib/python3.12/site-packages/scratchattach/eventhandlers/_base.py", line 82, in stop
    thread = self._thread
             ^^^^^^^^^^^^
AttributeError: 'TwCloudServer' object has no attribute '_thread'

So I guess I am doing something wrong... Does hosting a TW cloud server at home and access it from somewhere else possible?

Scratchattach version : 3.0.0b4
Tried OS : Windows 11, Linux Mint 22, Android 7.1.1 (using Pydroid)

Activity

  1. TheCommCraft commented on Jun 6, 2026

    @TheCommCraft
    Collaborator

    Would you please provide your full code?

  2. JloAu commented on Jun 6, 2026

    @JloAu
    Author

    Sure:

    server_ip = 'XX.XX.XX.XX'
    server_port = 35987
    
    server = sa.init_cloud_server( server_ip, server_port, length_limit=None, allow_non_numeric=True, whitelisted_projects=None, allow_nonscratch_names=True, blocked_ips=[], sync_players=True, log_var_sets=False)
    server.start()
    
  3. faretek1 commented on Jun 6, 2026

    @faretek1
    Collaborator

    This could be wrong, but in some cases, setting the server_ip to 0.0.0.0 will have a special effect that disables a firewall (this was the case when I used gorilla/websockets). It is definitely possible to self-host a cloud server

    Also is the other machine on your Local area network? Or are you trying to self host for machines outside of your LAN?

  4. TheCommCraft commented on Jun 6, 2026

    @TheCommCraft
    Collaborator

    I think the server ip is supposed to decide what clients can connect to your server. To allow your client machine to connect, you would need to set the ip to the address od that machine or to 0.0.0.0 (which allows all ips).

  5. JloAu commented on Jun 6, 2026

    @JloAu
    Author

    This could be wrong, but in some cases, setting the server_ip to 0.0.0.0 will have a special effect that disables a firewall (this was the case when I used gorilla/websockets). It is definitely possible to self-host a cloud server

    I think the server ip is supposed to decide what clients can connect to your server. To allow your client machine to connect, you would need to set the ip to the address od that machine or to 0.0.0.0 (which allows all ips).

    Okay, I'll try this in few days. So I set the server_ip to 0.0.0.0, and I put the external ip of my server in the TW url?

    Also is the other machine on your Local area network? Or are you trying to self host for machines outside of your LAN?

    At first the machines will be on my LAN (for my tests), but next I would self host for machines outside of my LAN

  6. TheCommCraft commented on Jun 6, 2026

    @TheCommCraft
    Collaborator

    For inside your LAN, you should use the local ip in turbowarp. For outside your LAN, you should use the URI that your port forwarding service provides. The 0.0.0.0 is at least the case for sockets and I believe that the convention holds for websockets aswell.

  7. JloAu commented on Jun 8, 2026

    @JloAu
    Author

    It doesn't work for both inside and outside my LAN...

  8. JloAu commented on Jun 9, 2026

    @JloAu
    Author

    The only thing I've been able to do is:

    • host a TW server on the machine that receives the port redirects
    • connect other devices (both inside and outside the local network) to the TW server using the same Python program (on the server side, I can see connections and handshakes)
    • When I stop the server, the Python scripts on the other devices crash (obviously) due to loss of connection
    • Regardless of the device (including the one hosting the server), I cannot communicate with the server with the Turbowarp project...
  9. TheCommCraft commented on Jun 9, 2026

    @TheCommCraft
    Collaborator

    The problem seems to be that scratchattach does not use a secure web socket

  10. Boss-1s commented on Jun 9, 2026

    @Boss-1s
    Contributor

    I believe I'm having the same problem....
    I can't connect to my custom websocket server with turbowarp over localhost and 127.0.0.x, only through opening a new terminal window on the same VSCode Codespace that is running the websocket script

  11. Boss-1s commented on Jun 9, 2026

    @Boss-1s
    Contributor
  12. TheCommCraft commented on Jun 9, 2026

    @TheCommCraft
    Collaborator

    You might need to use the address "0.0.0.0" in the server code

  13. JloAu commented on Jun 11, 2026

    @JloAu
    Author

    Is this fixable or should I use the TW cloud servers instead?

  14. TheCommCraft commented on Jun 11, 2026

    @TheCommCraft
    Collaborator

    Exactly what is your code and what url do you use for turbowarp? Maybe you are still doing something wrong because it is working for me.

  15. JloAu commented on Jun 11, 2026

    @JloAu
    Author

    Sure, here is my python code:

    import scratchattach as sa
    from scratchattach.cloud.cloud import CustomCloud
    
    # Init Server & Cloud Events
    
    server_ip = 'my external ip'
    server_port = 9080
    project_id="1321224718"
    
    server = sa.init_cloud_server("0.0.0.0", server_port, length_limit=65536, allow_non_numeric=True, whitelisted_projects=[project_id], allow_nonscratch_names=True, blocked_ips=[], sync_players=True, log_var_sets=False)
    server.start()
    
    cloud = CustomCloud(project_id=project_id, cloud_host=f"ws://{server_ip}:{server_port}", username = "JloAu", length_limit = None, allow_non_numeric = True, _session = None, header = None, cookie = None, origin = None, print_connect_messages = False)
    cloud_events=cloud.events()
    

    And here is the turbowarp link: https://turbowarp.org/1321224718?cloud_host=ws://[my external ip]:9080

    I use scratchattach 3.0.0b4

  16. 10 remaining items

  17. TheCommCraft commented on Jun 16, 2026

    @TheCommCraft
    Collaborator

    The problem with your firefox installation is that it doesn't seem to support websockets while chrome behaves as expected. To guarantee better support for the cloud server, we might need to implement ssl/tls for the underlying websocket server.

  18. JloAu commented on Jun 16, 2026

    @JloAu
    Author

    okay, will this also make the cloud server available outside the LAN?

  19. TheCommCraft commented on Jun 16, 2026

    @TheCommCraft
    Collaborator

    It might. You would probably still need to forward a port to get it working but that depends on your ISP and network settings.

  20. Boss-1s commented on Jun 16, 2026

    @Boss-1s
    Contributor

    Are you thinking of using a third-party provider

  21. JloAu commented on Jun 16, 2026

    @JloAu
    Author

    I don't think so... I'd like to try hosting it on an old tablet (I can forward a port). If that doesn't work well enough, I'll give Wispbyte a try...

  22. JloAu commented on Jun 25, 2026

    @JloAu
    Author

    hello, how is it going?

  23. TheCommCraft commented on Jun 25, 2026

    @TheCommCraft
    Collaborator

    I am still waiting for @faretek1 to approve the pull request

  24. TheCommCraft commented on Jun 25, 2026

    @TheCommCraft
    Collaborator

    You can use something like cloudflared to create a tunnel to your cloud server and then just use wss://<tunnel_domain> as the cloud host. A quick and easy way to temporarily create such a tunnel (if you already have cloudflared installed) is to use cloudflared tunnel --url http://localhost:8080 and use the tunnel url that the tool provides. 8080 should be replaced with the port you are using.

  25. TheCommCraft commented on Jun 25, 2026

    @TheCommCraft
    Collaborator

    There will hopefully soon also be a more detailed explanation in the wiki.

  26. JloAu commented on Jun 25, 2026

    @JloAu
    Author

    You can use something like cloudflared to create a tunnel to your cloud server and then just use wss://<tunnel_domain> as the cloud host. A quick and easy way to temporarily create such a tunnel (if you already have cloudflared installed) is to use cloudflared tunnel --url http://localhost:8080 and use the tunnel url that the tool provides. 8080 should be replaced with the port you are using.

    I just tried it, and it works perfectly outside my LAN, even on Firefox. Thank you!

  27. TheCommCraft commented on Jun 25, 2026

    @TheCommCraft
    Collaborator

    Just remember the quick and easy solution is only temporary. To permanently tunnel, you need to consult the cloudflare documentation.

  28. JloAu commented on Jun 26, 2026

    @JloAu
    Author

    yeah sure

  29. JloAu commented on Aug 18, 2026

    @JloAu
    Author

    Hello, I just tried the version 2.2.1, which has sa.init_ssl_cloud_server(), and I get the following error:

    (.venv) jloau-mint@jloau:~$ /home/jloau-mint/.venv/bin/python /home/jloau-mint/Documents/Scratchattach
    Traceback (most recent call last):
      File "/home/jloau-mint/Documents/Scratchattach", line 5, in <module>
        server = sa.init_ssl_cloud_server("0.0.0.0", 8080)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/jloau-mint/.venv/lib/python3.12/site-packages/scratchattach/eventhandlers/cloud_server.py", line 716, in init_ssl_cloud_server
        return TwSSLCloudServer(
               ^^^^^^^^^^^^^^^^^
      File "/home/jloau-mint/.venv/lib/python3.12/site-packages/scratchattach/eventhandlers/cloud_server.py", line 493, in __init__
        SimpleSSLWebSocketServer.__init__(
      File "/home/jloau-mint/.venv/lib/python3.12/site-packages/SimpleWebSocketServer/SimpleWebSocketServer.py", line 729, in __init__
        self.context.load_cert_chain(certfile, keyfile)
    TypeError: certfile should be a valid filesystem path
    Exception ignored in: <function BaseEventHandler.__del__ at 0x75ae429676a0>
    Traceback (most recent call last):
      File "/home/jloau-mint/.venv/lib/python3.12/site-packages/scratchattach/eventhandlers/_base.py", line 73, in __del__
        self.stop()
      File "/home/jloau-mint/.venv/lib/python3.12/site-packages/scratchattach/eventhandlers/cloud_server.py", line 676, in stop
        thread = self._thread
                 ^^^^^^^^^^^^
    AttributeError: 'TwSSLCloudServer' object has no attribute '_thread'
    

    Here is my code:

    import scratchattach as sa
    server = sa.init_ssl_cloud_server("0.0.0.0", 8080)
    server.start()
    

    Am I doing something wrong?

  30. TheCommCraft commented on Aug 18, 2026

    @TheCommCraft
    Collaborator

    You need to provide certfile and keyfile to init_ssl_cloud_server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions