Skip to content
Sign upLog in
← Back to Community
Multiplayer
Profile icon
hacker
has Hacker Plan
JacksonSmith2

Would it be possible to use a repl as a server host and then have python scrips connect to it like a client? Like to make a repl called server, and then connect to it from a python script on my desktop, transferring data between them? Or is this not possible?

Voters
Profile icon
JacksonSmith2
Comments
hotnewtop
Profile icon
SixBeeps

You can make a Flask server, which will give you an IP to connect to. From there, you can make HTTP calls (with something like urllib) and interact with it from there.

Profile icon
techde

@SixBeeps
Ok then, RIP both Epic gamer's and me's comments!

Profile icon
JacksonSmith2

@SixBeeps
I tried this with the flask code:

from flask import Flask app = Flask(__name__) @app.route("/", methods=["POST"]) def welcome(): return "TEST\n" app.run(port=2112)

and the urllib code

import urllib.request import urllib.parse url = 'http://127.0.0.1:2112/' x = urllib.request.urlopen(url)

but the urllib code keeps returning an error, saying urllib.error.URLError: <urlopen error [WinError 10061] No connection could be made because the target machine actively refused it>

Profile icon
SixBeeps

@JacksonSmith2
127.0.0.1 will always refer to the computer that's running the code. In other words, if you're running the urllib code on your local machine, then you're trying to connect to the server that's running on your PC (which is likely none). You'll need to grab the public IP and connect to that.

Profile icon
JacksonSmith2

@SixBeeps
How would I access the public IP?

Profile icon
SixBeeps

@JacksonSmith2
If you use the Flask template, it'll print it out in the console
image

Profile icon
JacksonSmith2

@SixBeeps
I changed my url to x = urllib.request.urlopen('http://172.18.0.1:2112/') as that is what was returned and now I get the error [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond>

Profile icon
techde

The term server, is a bit confusing to me, what do you mean by server, but if you mean some sort of sending and receivng database, repl has its own db called well.. REPL DB!

Profile icon
EpicGamer007

I believe this is possible, but just to let you know, repl.it only supports http servers, as it is a website. because of this constraint, you will have to have your programs connect to an http server instead of a real server

Profile icon
techde

@EpicGamer007
Yes, good explanation. This deserves the cycles not mine but if you don't know how repl db works check out
@Coder100
's tutorial ALL CREDITS TO HIM: https://repl.it/talk/learn/Replit-DB/43305