2

I am writing a simple javascript game for a webpage. I am going to convert it to the desktop using tidesdk. I would like to allow players on different machines to play each other without the need to communicate through a server.

  1. Is this possible in general? Is this Sockets?? Do you have any links of this being done with javascript code?
  2. Is this possible with TideSdk? Do you know of any links to examples of this being done wiht TideSdk?
  3. How do the players know what ip address/port their machine is on so they can give it to the other player?

I am sorry these are vague and open questions, but I don't really know where to start looking for this stuff, as I don't really know what the stuff I am looking for is called.

... Oh, and I don't want to use any third party stuff if I can help it. Maybe the jquery at a push.

Rewind
  • 2,554
  • 3
  • 30
  • 56
  • Without some server, whether you host it or by a third party, I can't think of a way to accomplish this. WebSockets are probably what you'll need if you want "live" gameplay, but it needs a server to manage the connections. I've never used TideSDK, although it looks cool, so they might have something special for this – Ian May 30 '13 at 16:32
  • Seconding Ian, WebSockets are your likely answer. You'll need some kind of server in that case, but at least you can approximate real time peer to peer. I suggest looking at NodeJS to build your WebSocket platform on. – Matt Holmes May 30 '13 at 16:58
  • 1
    WebRTC is what you want. But you would still need a server to initiate the communication between players. But once you have that it will be p2p. – PeeHaa May 30 '13 at 18:18
  • Thanks for your answers. I look into these. – Rewind May 31 '13 at 11:04

2 Answers2

3

This would be impossible with the APIs provided by web browsers (you would need to use something like Socket.IO and communicate through a server, as others have said). Fortunately, since you are using TideSDK, it is possible as long as you don't need a lot of network efficiency. You will need to provide a server, but it will not have to be powerful enough to host the actual games.

The General Client and Server Method

There are other ways to organize a network, but you can look those up if you think they'd be easier to implement.

Your server will host the actual game download and provide matchmaking capabilities. The clients that people download will contact this matchmaking server to find others who want to play.

The matchmaking server should select one of those clients to be a host for the others. Finally, the matchmaking server will tell the client selected as a host that it is the host and give it everyone's connection information (ports and IP addresses) while giving the other clients the connection information for the selected host. The host will connect to the other clients.

The host computer will be the only one that actually does any processing of gameplay, and the other clients just display whatever information the host sends them. The clients render the current state of the game from each player's perspective on their respective computers and capture user input, which is sent to the host for processing.

Implementation

TideSDK provides a Ti.Network.TCPSocket object which can make raw TCP client connections to TCP servers. Unfortunately, it does not also provide a way to make raw TCP servers. Instead, TideSDK provides a Ti.Network.HTTPServer object, which implements the HTTP protocol server over TCP, and a Ti.Network.HTTPClient object, which provides an HTTP client (it is actually just an abstraction over the normal AJAX request API). You can use the provided HTTP server on the host computer and directly connect to it on the clients using the provided HTTP clients. Data will be exchanged using the HTTP protocol. As far as I can tell, this is your only option here.

I did not find any example code out there (beyond what is in the TideSDK documentation) but you might find some if you are really interested.

Next Steps

If I wanted to go ahead with using TideSDK, I would do the following:

  • Tell the developers of TideSDK that you are interested in a TCP server socket. A raw TCP connection would be much faster than HTTP.
  • Test out the HTTP connection and find out if it is fast enough for my game.
Michael Younkin
  • 788
  • 6
  • 11
1

Yes it's possible in general, and sockets are what you need. Although I don't think it's possible in practice, here's why.

Normally in a P2P game, there would be a server that knows who is online, and what their IP is. When new players connect to the server they will see a list of other users, they can select who they want to play.

Without having the server, there will be no way for users to see who is online, and to answer your 3rd question:

  • How do the players know what ip address/port their machine is on so they can give it to the other player? It doesn't matter if they can find their own IP, they have no way to find the IP of the opponent (without calling them on the phone :)).

So, if you want to build a game, then you'll need a server. I suggest Node.JS alongside Socket.IO

Drahcir
  • 11,772
  • 24
  • 86
  • 128