Socket.io backend hosting on another site

Problem

I have been trying to create a real time multiplayer tic tac toe game for my website. I found socket.io so i decided to try it out. I have a copy of my website files available locally and i have installed node.js and npm.
I set up some stuff locally and by running the server using nodemon on port 80 i am getting proper console logs on my terminal.
However i now realize that infinity free doesnt support node.js or npm and from what i understand my pc is acting as a server for the backend right now.

So i was wondering if its possible to host the backend permanently on replit or any similar site. Assuming it is possible, can the infinity free server even communicate with the replit server (the html file on infinity free needs to load script from replit is what im guessing).

I read that most ports are disabled on infinity free except 80 and 443. 80 is used for http but on googling it is recommended to use the same port for socket io anyway.

PS. Im new to this stuff and ive never worked on backends before so any help would be appreciated

Clarification

  1. Can i host socket io backend on replit or similar site permanently
  2. Can the html file on infinity free then load a javascript file from replit
  3. Is this even possible due to most ports being unavailable on infinity free

Website URL

https://www.tictactoe.great-site.net

If all you’re hosting with us is plain HTML, and all of the application logic is captured in either the Socket.io server, or in your frontend Javascript code, then there is nothing to worry about. In that case, all Websocket stuff doesn’t interact with our servers in any way. The only thing our hosting would be doing is serving the HTML files, which is so simple you could basically host it anywhere.


If you also want to do server side logic on our hosting, it becomes more complicated. We only support PHP as a server side programming language, so you’d have to interact with the websockets through PHP. Websockets is mostly just a layer on top of HTTP, so you should probably be able to emit messages to it even with the limitations of our hosting (and web hosting in general), but running a PHP process to receive messages is not going to work.

6 Likes

well i have javascript file for the backend that manages all the socket.io stuff, the problem is it has to be run using nodemon or a node.js server

but how will i send data to your servers using replit.
i did try something but couldnt access the html file on the server (i tried to give it a url http://www.tictactoe.great-site.net/playonline.html but it was only trying to find a folder locallly with the link as the name, and now somehow my account is temporarily suspended)

so can i send arrays or objects from one user to another with php using websockets?

once again, i have barely any clue what im doing so i might be misunderstanding stuff here

2 Likes

The problem you’re describing doesn’t really click for me as for how you want the final result to look like, so maybe there is indeed some misunderstanding about how things work and are supposed to work.

If you only need to send messages between users, you may not need a server component at all. A quick Google search tells me that Socket.io has the concept of Rooms that lets you send messages to groups of players directly. If you could make a room for every game match, you could just send game moves directly from player to player without any additional logic on the server side.

But to be clear: I’m not that familiar with Websockets in general, and definitely not with Socket.io, so don’t take my word for it.

If you have a backend in Node.js, you cannot host it with us, because we don’t provide Node.js hosting.

In theory, you could run your Node.js backend on Repl.it, and transfer data to another server from there. I would normally suggest making HTTP calls to the website backend hosted on the web hosting, but this will not work here due to this security system: Ensuring only web browsers can access your website

But you could also ask yourself whether you need any data to be sent to our servers in the first place. If all you need to do is send game events between two browsers, what purpose do our servers have in this?

5 Likes

i was planning to send an array or an object that contains the game state to the opponent then allow them to make a move and again send it back

Im pretty sure once again it requires a backend server to communicate with the frontend since the players are technically the html files that are being loaded in your server

ig ill try to do it with php because i think someone already has done it and there seems to be socket.io on php called elephant.io but that once again may require a server but if it is php then i think i can just host it on infinityfree

i cant think of anything else, how else can i send game events between two browsers without involving your server that is hosting the file
hmmm but it did kind of give me an idea, maybe i can make a new html file each time and 2 players (idk how i can identify them but maybe ill have to implement an accounts system then) will be redirected to that file then all changes to that file can be made in real time

In any case whatever protocol you use
you need a place (server) that will connect two strangers initially
and after that they can share data with each other via browsers.

But I don’t know if it’s even worth wasting so much time (unless you want to learn something along the way) to a game where whoever plays first wins ?

If the game is Gomoku (5 in a row) which is like chess and I like to play that
then it would make sense :smile:

The next problem is that you must have space for chat between two players, otherwise everything is boring and stupid.

6 Likes

alright ill look for something there if WebRTC can not work here

makes sense but once again can that server be infinityfree?

Im planning to make chess after this but wanted to try something simpler first and gomoku doesnt seem like it will be too hard to implement in the already existing tic tac toe so ig i can try that aswell.

well socket.io would have have been perfect for this but im guessing i can accomplish the same using WebRTC or websockets

If you want to send events between browsers, you can do exactly that: send game events between the browsers. If you do that, then there is no need to have any server in between to exchange messages. WebRTC is the protocol to do that.

Because WebRTC is client to client, I’m pretty sure you don’t need any server side component to make it work. After all, the server is not involved in the messaging.

Socket.io is an implementation of a Websocket server. Websockets are useful, but Websockets are a client-server protocol. If you want to track game states on the server, validates moves and what not, it can be useful, but you could also implement that client side.

“The server” can be anything in that case. If you want to host your Node.js/Socket.io application with Repl.it, then Repl.it provides “the server”. If you do decide to go the Websockets route, there is no need to exchange any game data with our hosting. Unless of course you want to build specific features where you do want this.

Our hosting can be used just fine to only host the HTML and browser Javascript code for your game, without any additional connection handling or data processing being done here.

6 Likes

ok i will go ahead with WebRTC.
Google does tell me that for most real world applications WebRTC does need a server but for one to one connections it isnt nessecary. Ill still try it out

Alright thanks for clearing that out

WebRTC is a client-to-client protocol, but you may need a server to do the initial connection setup. I have no idea how that works technically or whether you would be able to host such a thing with us. But you could host that with Repl.it too if you want to.

2 Likes

i think ive gotten it working
im using pubnub as a signaling server.
So far it is working perfectly locally and im able to send data from one client to another
im fairly positive it will work on your servers as long as this simple tag works

<script src="https://cdn.pubnub.com/sdk/javascript/pubnub.8.0.1.js"></script>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.