Ask coding questions

← Back to all posts
Is it possible to use python's socket library in repl.it?
ETHANSIAO (41)

Hello,

(Quick disclaimer: this is a question about the feasibility using sockets in repl.it, not about how to use the library itself. Also, I'm definitely no expert whatsoever. Thanks!)

I've been trying to expand my own knowledge about python, and I've wanted to start learning more about online networks, clients, servers, etc. I've been watching a tutorial about python sockets here: https://www.youtube.com/watch?v=Lbfe3-v7yE0

After running the code demonstrated in the video, nothing happened. Is it possible to use python's socket library in (specifically) repl.it? I'm aware that javascript's socket library can work here, but I'm not quite sure about python's socket library.

If helpful, please see this code: https://repl.it/@ETHANSIAO/CheapDemandingDecompilers

Thanks for your time,

-E.S.

Answered by 21natzil (1176) [earned 5 cycles]
View Answer
Comments
hotnewtop
21natzil (1176)

Yes, and no. Yes you can create sockets, and they will behave normally. The problem with your code is that you're using gethostname. Replace that with "0.0.0.0" which means it will bind to the computer, but be accessible externally. The reason I say no, is that whenever you open a socket and bind it to the repl, repl.it is tricked into thinking you started an HTTP server (A web server). It will then start requesting your website, which may cause issues with your code. It will also convert any request other people made to the repl into HTTP.

ETHANSIAO (41)

@21natzil Got it, thank you so much for the help!

OwenBradstreet (124)

@21natzil How would you go about connecting to the server from another repl?