Socket not connecting
I'm trying to get two repls to connect using socket. I created some code using a tutorial, but for some reason, I can't get it to work. Here are the repls:
https://repl.it/@AtharvGoel/ServerTest
https://repl.it/@AtharvGoel/ClientTest
Voters
Froggo-School
don't know what language it was written in, but for future reference, an example using python's socket
library:
import socket tcp_connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM) udp_connection = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # otherwise, functions are the same.
Coder100
Your server needs an HTTP socket server.
AtharvGoel
@Coder100 How do I do that?
abc3354
@AtharvGoel @Coder100 This is not websocket, you don't need an HTTP server
I'm sorrry but I don't think replit supports tcp servers
You can try to ask for the feature at repl.it/feedback
There is a way to do it using ngrok, I can explain it quickly if you are interested
@abc3354 If you can explain it to me or refer me to something, that would be great.
@abc3354 I tried using pip install ngrok but got an error
@AtharvGoel I created something to help you
It is based on https://dashboard.ngrok.com/get-started/setup
install-ngrok.sh
and paste thatctrl - shift - s
) and typeyou need to create a ngrok account at ngrok.com

copy the command with your authtoken
paste it on the shell (
shift - insert
to paste)type

./ngrok tcp 5000
(5000 is the port of your server)The intersting thing is the forwarding part (
2.tcp.ngrok.io:15792
for me)you can use this to connect to the server
For example in the client with my address it will be
You can see a working repl here
https://repl.it/@abc3354/ngrok
https://repl.it/@abc3354/ngrok-client
Hope this will help :)
PS: if the repl is public, your authtoken could be exposed (I'm not sure) , go on this page to reset it
@abc3354 I ran your example but I got an error on ngrok-client
Traceback (most recent call last):
File "main.py", line 10, in
s.connect((TCP_IP, TCP_PORT))
ConnectionRefusedError: [Errno 111] Connection refused
@abc3354 I GOT IT TO WORK!!! It didn't save the stuff in the shell which was the problem. Is it possible to get this to work over different devices?
@AtharvGoel did you run the server first ?
I think you will have to fork it and use your own ngrok authtoken to make it work
@abc3354 Yeah, I got my own to work using your help, do you know if this works over different devices.
@AtharvGoel congrats ! :D
It should actually work over different devices :)
@abc3354 Ok thanks
@abc3354 I'm having some problems. When I try to decode the message on the client side, nothing shows up. On the server side, the message won't show up at all.
@AtharvGoel I have the solution !
On the client I replaced
s.send(message)
bys.send(message.encode('utf-8'))
, to have a byte arrayAnd in the server I added a print (to actually show the message received)

@abc3354 You can use the .env file.
@AtharvGoel How did u get it to save ?
@abc3354 is it possible to use ngrok with java? or is it python-specific?
@WassimTahraoui ngrok should work with any language ! Note that if the repl is public, someone could steal the auth token replace your tcp server with an evil one !
@WassimTahraoui
I just tried my repls again and it seems that you cannot connect to ngrok with tcp anymore
That means that the server repl stills work but the client repl does not