This could do with a bit more detail on Socket.IO. Its more than just a web socket client library, more a library for real time communications on both the server and client side, that just so happens to use WebSockets when they are available (it starts with long polling), and throws in a lot of other features on top, such as broadcasting and namespaces.
The issue with using Socket.IO with Python is that Socket.IO expects to be talking to its own JS server, running under Node.JS. Of course, people have reverse engineered the protocol and written servers in python, but the one in the article, flask-SocketIO <strong>does not work</strong> with the 1.X releases of the client libraries, as the protocol has changed.
I would put the Socket.IO stuff in a separate section, and make quite clear that this is an optional layer on top of WebSockets.
WebSockets are somewhat more complex than AJAX requests. WebSockets are seeing increasing popularity and are fairly enjoyable to learn about. If you'd like a good resource to experiment with them check out this: http://socket.io/get-started/chat/
This uses a NodeJs and Socket.io as the server platform.
However AJAX can work with your existing PHP scripts. This would probably be easier for your project as you could have an AJAX call to a PHP file that checks for messages every 10 seconds or so.
To conclude WebSockets are fun and the future of interaction between the client and the server on the web, however AJAX would be a better implementation for your needs in this case. As Mahn pointed out the best resource for this is the jQuery ajax docs page: http://learn.jquery.com/ajax/
Please please use web sockets .. it's 2014 D:
An interval to spam an ajax request is ugly and limited.
If you are afraid of web sockets compatibility you shouldn't, people using old IE/FF/Safary are really rare now. Even rarer in a gamer community.
With that you could easily have a real time image of each users cursor on the map, which would be nice to explain battle plan or positions. Even add animation when the user click or drag (or a multilayer paint).
Then server side I'm not sure what you're using but I know implementing a web socket protocol is not hard using asp (SignalR), nodeJs (socketio), php (socketo).
Edit: Nice work tho
This is a subjective question, of course, but I'd suggest that you go with Node for the backend because it simplifies your tech stack a lot. Since you'll need Node and its build tools anyway for the frontend framework (like React or Angular), it's probably easier to just use Node for the backend too.
I think that it could work well if you used Socket.IO to communicate game events in real time. This example game might be of some help to see how you can implement a multiplayer game.
If the Socket.IO server has the same origin as your web server, you should be able to use your existing session identifiers because they will be passed as cookies during the web socket handshake.
You would register middleware functions to check the cookie. There's an [example](http://socket.io/docs/server-api/#namespace#use(fn:function\):namespace) hidden in the Socket.IO docs:
var io = require('socket.io')(); io.use(function(socket, next){ if (socket.request.headers.cookie) return next(); next(new Error('Authentication error')); });
You'd obviously want to validate the cookie a bit more than that.
If the servers have different origins, you will need to pass the session identifier in as a custom Socket.IO event. It's not a lot of code to do this, but I would consider using a package like socketio-auth. My app uses JWTs so we use socketio-jwt which is very similar.
So you could do this with a database trigger, but often that's not a great architecture choice. I've built several messaging systems and we did it using a message queue, something like RabbitMQ.
The idea being that when a client posts a message, it goes to an api endpoint and gets processed. The code there puts that data into the db and also puts a message on the queue indicating a new item is available, with the message encoded on there.
In the background you have a series of services listening for those messages and start processing them. You can use a realtime library like socketio or signalr to push realtime updates to clients.
If you don't want to use a realtime framework, you can just have hte client poll, but that adds unneeded chatter. We have realtime frameworks, we should use them.
In our application, on launch the client makes an api call to get all messages it cares about for a given period of time (now - 1 hour). After that it registers itself with one of the services. Now when a message comes through, the service can decide which clients to send to etc.
You can have the service be a load balanced cluster to scale easily.
Personally I don't like the idea of a database initiating a workflow from a trigger. To me a database is a data store that's it, I'll handle workflows and decision trees at other levels. I want to keep the database as a pure database it's easier to scale out that way and easier to swap out if need be . Though in my career as an architect, I've rarely had to swap out DB's, but they do happen and better safe than sorry. Also with this type of architecture introducing a caching layer before the DB is trivial.
I'd stay away from flash for now, it's dying off and you can't use it everywhere (iPads for example). That being said, if your game is realtime you can use all JavaScript.
There is a new technology called WebRTC that allows computers to connect to one another using JavaScript. A very nice library for working with it is Peer.js.
Of course, your game wouldn't be 100% cheat proof if it's all client side, but that would be okay if its friendly. To begin with, I'd work out the JavaScript of building your game between two people using Peer.js. Sending messages back and forth as to who has what card, what cards are visible and where they are on the playing surface so you can move them around.
A long time ago I built a node.js application that let you play checkers with someone else. One person's web page would contact the server and open a websocket, same with the other person's, and when a piece was moved, jQuery would send the data over the two and it would show up on the other side. I used socket.io for that.
Cheers!
Edit: All of those technologies have some awesome tutorials.
Just to continue this for other people, modern web development is SO rewarding when you learn it to it's fullest understanding.
To expand on buckus69's comment, I have a client (firefox, chrome) and a server (apache, IIS) and make them talk to each other. This is the basis of a web application and with those two servers particularly, this is stateless, as in not a persistent and OPEN connection.
For example, after a new user fills in a form the form POST to the server, the server add's that data to a database and sends a RESPONSE back and CLOSES the connection.
You see? It's not open 24/7, they talk only when they need to fucking talk. So a thing like let's say a chatroom is not exactly suitable for that type.
Now, a truly open connection aka SOCKETS supports an open connection until you close it.
BSD sockets which linked above is an example of that.
http://socket.io/ is an open connection between a client and server (node.js). That is suitable for a chatroom app, I hope this clarifies some things a bit.
Source: Professional Full Stack Web Developer
Get into web dev, as more and more software moves to the cloud you'll be a step ahead. I encourage you to become a Full Stack Dev also, you'll have the luxury of every company wanting you and the ability to not have to delegate certain task to people.
I replied to you elsewhere. socket.io is a great node.js library that makes this dead simple. You could also look into running jabber on the server and using some generic client library like this one.
Google used to use XMPP for its google chat so it's a robust protocol and the open source jabber project does a great job implementing it. IIRC Whatsapp uses a custom built erlang back-end, and I'd avoid that until you have some more programming experience.
Cheers!
I've attempted making multiplayer games in so many languages. Node has by far become my favorite for working with web sockets. If you are doing a web based game, I highly recommend checking out socket.io http://socket.io/docs/#
> I don't know how to ask a socket (client) for an input
check out http://socket.io
> Another trouble is that I don't know how to make the game to wait for a second client to start the game
Using socket.io, keep a list of connected clients. Once there is more than one client, emit a "game start" event or similar.
[edit] Just read the "and only bash" part -- what exactly do you mean? Is your app hosting a telnet server or something? Or is it just a CLI, and if so, what do you mean by "multiple clients"?
You could set up a simple Websocket server using http://socket.io on Node, and then make the "sending" apps make HTTP REST calls to your websocket server, which in turn relays the message to the browser using Websocket/socket.io.
You could of course use raw Websockets from both the "sending" app, the server and the "receiving" app, I don't think it's too hard!
yes, you need a server
communication can be done for example with websockets, you might want to check out libraries like http://socket.io/
and edit: you dont need rails for that, if you know any programming language except javascript you can use it for your server, if you dont you can use javascript with nodeJS for that job
You may want to look into node with web sockets. It would allow you to still have live updates, but would remove your user limit. Of course you'll need a host that supports node.
Edit: Here is the package I'd use: http://socket.io/
That is a nice color.
I'm a fan of bright purple and pink gradients. I'm redesigning my personal site and I have a darker variation of the combo right now. I like the accent colors on socket.io, although they could be more prominent. This header is amazing at page load (changes over time).
I also like using very dark greys (like yours) for blacks and slightly off-white greys for white backgrounds.
> load socket.io from a file that doesn't exist
actually this is a recommended path for developing apps with socket.io. See http://socket.io/docs/
Socket.io handles that path and resolves it with the client library for you.
You're right though that this shoud resolve the problem OP is having.
Since you're talking about an online multiplayer game, you will need some way of the two players to connect to each other. Since web browsers can't connect directly, you need a game server that both users can connect to, that handles communication between them.
Now, you'll have to set up this server yourself, and most likely write the code to run it too. If you're used to writing JavaScript code (as I assume you are), then you can use node.js to write a server in JavaScript, and socket.io to connect your game and server. (Here's a demo of a game written using socket.io)
There are a few ways to accomplish that. Modern Javascript implementations support WebSockets, in which case, yes, there is a mechanism on the client listening for updates from the server. In most cases though, the client just periodically polls the server for updates. There are libraries that will automatically select the best listening method available. See: http://socket.io/
They don't work through the mandatory proxy we have at work, so it's not just browser incompatibilities you'll run into. I did actually put a ticket in with our IT department about it, and the answer was they'll be happy to support them as soon as the proxy itself does. Until then, I can't run anything that needs websockets at work. Lots of other people are probably in the same boat.
That said, you might look at socket.io, which will use websockets if it can, and fall back on other things if it can't. I don't know how that fits in with IIS though, it might restrict what you can use for your back end a lot more. It's meant to be used with node.js, but I've gotten it to work (on a toy project, not anything "real") with TornadIO too.
Yeah, and those Flash servers aren't even particularly good.
Here's some links to help you get started!
A single page app is basically a web page that only loads one page request, so new data is loaded either via XHR (AJAX) or websockets.
Your question is a bit unclear and I dont know what kind of data you are requesting so I can only make a limited suggestion.
The most common setup is to use websockets to connect the browser to the nodejs server (see socket.io) and when the server has new data from the API, it sends it to the connected browsers. The browser then receives this typically as JSON data and renders it into the DOM, often with some HTML templating to make styling easier.
A typical example is a chat app, where all users are connected to a nodejs server and anytime someone post a message, it is rebroadcast to everyone else.
You can use frameworks like metor https://www.meteor.com/ but I would start with some of the socket.io examples (http://socket.io/get-started/chat/) and build up from there.
You don't "create" rooms in Socket.IO, you simply make users join the rooms and any events emitted will go to anyone in that same room. See the docs here.
It's just a case of using: socket.join('some room');
to have a socket (user) join a room.
Then emitting events to that room: io.to('some room').emit('some event');
.
And you can disconnect from that room: socket.leave('some room');
.
Have you checked the socketio docs about running it on multiple nodes? Clustering is the way forward (and I mean multiple nodes, not just using the nodejs cluster) as you deduced as well. You will need a redis cluster as well (heroku has some options for that I think) to synchronize messages between your nodes.
You will probably see a drop in performance due to serializing/deserializing data, not using in-memory store and the addition of another layer (redis). This is unavoidable, but probably the only way to scale out (AFAIK).
Finally, there are some tips about useful nodejs options and things to keep in mind for websockets in this article. It is over a year old so double check if the facts still apply (for example socketio is now compatible with the nodejs cluster module, you can find it in the docs I linked at the top.), but generally the configuration applies.
I hope it helps and good luck!
That sort of question has an answer too long for a reddit commit. It's a pretty standard extension for the http://socket.io/get-started/chat/ tutorial case that you'll find nice guides for. All a "room" is, is just a subset of users. A simple map structure would work.
Websocket servers are harder to scale because they involve persistent connections compared to the transient, stateless connections you deal with on a traditional request/response server.
For example, here's Socket.io's shitty worthless docs on the matter: http://socket.io/docs/using-multiple-nodes/
Afaik, you generally have two options:
Or some mix of the two. Obviously the ideal is that you never need more than one server because the move to two servers increases your operational complexity a lot since you need to depend on more moving parts like Redis or a load balancer or whatever.
10 million clients tho? lol, jesus mate. by then you're surely operating a profitable company and can put your crack team of websocket experts to the task.
The simplest you could go is to use something like flot a JS library that does realtime plotting. All your clients will listen on websockets like this provides for new data. When your sensors get new data, they both push to the database and the server so all the clients are updated.
Cheers!
No problem! I have some history of doing robotics (UAVs) and interfacing with electrical/sensor networks so if it's similar to what you're doing feel free to PM me.
I'm not really qualified to speak about Ruby/Python, my experience is primarily in Python so I'm biased. I know the bindings to OpenCV (what I used for processing video streams in the past) are good over there as well as making a server is dead simple. Ruby is about as easy from what I've heard.
For real-time chat I'd recommend going with node.js, it's just JavaScript both server and client side and there is an excellent library I've used in the past for p2p chat called Socket.io (link is to a tutorial for multi-user chat, only about 100 lines). You can also do it in other frameworks, but it's more difficult to handle since you'll want to do more pushing than have clients keep doing GET requests. You could look at other languages' websocket libraries to do something similar, but Socket.io also does a bunch of stuff to support clients that don't have websockets.
Cheers!
Not a full, extensive introduction, but here's a start: http://socket.io/get-started/chat/ Useful application that should show you some basic node usage and two of the most popular modules, socket.io and express.
You could use websockets and get the server to push changes to the clients. socketio might be a good place to start. I'm not sure why your global store would become invalid for the use case you're suggesting though.
Long-polling (what you are currently doing) is not really a hack in my opinion and is a completely valid solution. It may not be the most elegant solution but it is a solution that is widely used. The major drawback to long-polling is that you are hitting the server with a request that may return no known updates. This may be a bad thing when you have a significant amount of concurrent users. I can think of two immediate solutions off the top of my head. One would be to use Server Sent Events and the other would be to create a socket connection.
Server sent events are a one-way street. You basically create a JavaScript EventSource listener that will parse the incoming data and you can then apply it accordingly. Keep in mind that EventSource, to my knowledge, is not supported on Internet Explorer, so you would be missing out there. I am sure there is another solution for IE out there but I am just not all that familiar with it. Maybe another redditor can chime in... Anyway, remember with Server Sent Events you are listening for data but you aren't delivering data the same way. For updating data on the server you would use your typical POST and PUT HTTP methods.
Socket Connections create a duplex communications system that allows you to send and receive data through the browser. A socket connection would be made to each user currently viewing your page. Technologies like http://socket.io/ have most of this figured out for you. I haven't used it but it seems like the defacto framework for creating socket based web applications. But you could always roll your own code too :)
Some people here mentioned some ways to solve this but I thought I'd list two others.
One is long-polling which an AJAX request is sent to the server with the current state (online/offline) and instead of like /u/resilience19 mentioned with jQuery re-running the request every 15 seconds the request loops on the server every 15 seconds until it detects a change (e.g. offline -> online) then delivers the response.
Another option is using WebSockets. Something like socket.io. Essentially instead of repeatedly requesting a value to see if it's changed, a connection is left open and when the value is changed the server notifies the browser. Like push notifications. This method is used for things like messaging, rather than having to continually check if a message has been sent the server "pushes" the message.
I assume you want to log the chat for infinite scrollback or dispute resolution.
I'd recommend using websockets because they can do "realtime" communication and probably something like nodejs or go because both have fantastic support for websockets. Take a look at the socket.io chat example. If you add a few more lines you can get rooms and p2p messaging quite easily.
Edit: You will be able to run that on your server quite easily, and database integration should be a snap; you may even want to use sqlite to make it even less resource intensive.
If you just want to listen to the mic and stream events back and forth all you should need is plain old Websockets (https://www.npmjs.com/package/ws)
The other option for Websocket support would be socket.io (http://socket.io/)
Both modules should get you started in the right direction.
If you need the MQTT protocol then it looks like this is the module you're looking for - https://www.npmjs.com/package/mqtt. I've never used it so I can't say much about it other than it's the first google result.
Hi Miguel, I love flask-socketio, and we happily use it for chat applications. However, we would like to use it also for sending binary data for audio for multimodal dialogue systems which if I am not mistaken requires lates Socket.IO 1.0 (http://socket.io/blog/introducing-socket-io-1-0/#binary). Are you going to support it? Thanks for your work, and sorry for slightly of topic question.
I was working on a Unity/Websockets project just a few weeks ago. We used Node/Socket.io on the server side, and this open source Socket.IO plugin for Unity to get it speaking to the server. It was really easy to set up and get the two sending messages to each other. Hope that helps!
Well you could run your own Socket.IO server for "free". Here are couple tutorials.
http://blog.nedex.io/laravel-5-1-broadcasting-events-using-redis-driver-socket-io/
http://www.codetutorial.io/laravel-5-and-socket-io-tutorial/
http://socket.io/ is a popular library that comes with a server-side (Node) and client-side component that talk to each other. There's a lot of resources on it, but it's own documentation strangely sucks.
Here's what it kinda looks like:
Client-side:
var socket = io('http://localhost:3000');
socket.on('connect', function() { console.log('Connected to socket server');
socket.emit('hello', function(response) { console.log('I told the server "hello" and it responded with', response); }); });
socket.on('disconnect', function() { console.log('Disconnected from socket server'); });
Server-side (Node.js) - just kinda winging it:
var io = require('socket.io'); var httpServer = require('http').createServer();
var serverSocket = io(httpServer);
serverSocket.on('connect', function(clientSocket) { console.log('a client connected');
serverSocket.on('hello', function(clientCallback) { console.log('client told me "hello", so I will respond'); clientCallback('greetings, client!'); }); });
So basically the server starts up and listening for the "hello" event and then it responds to the client that's saying hello by passing its response into the client's callback.
You will need a server to handle online interaction and maybe database if you want to store data.
If your multiplayer game require near to real time performance, i suggest http://socket.io
I have written a similar application here: http://sonic.vulpes.pw (open two tab to see two character interact together). Using socket io and the source is here : http://github.com/cupnoodle/multi
For the frontend, use Cocoa Touch that you've already learned..
Hook it up to node via plain HTTP calls or something like Socket.IO if your app is doing some realtime data shit. You can use both in a RESTful fashion
What parts of this thing don't you get: http://socket.io/get-started/chat/
All you have to do is separate the loading of the express module and creating the app instance like so:
var express = require('express'); var app = express();
You can then add the bit where it serves static files:
app.use(express.static('public'));
Really. You NEED to understand what's happening. No one will hold your hand.
I think it would really help you to read the documentation for Socket.io. I hope you don't read that as rude, I just honestly think you should look at them.
What you want is to create rooms.
io.to('postsWithTags').emit('some event'):
To be honest, .io companies are more B2B than B2C. So I would recommend going for the .io.
They are almost always related to SaaS businesses.
Examples : http://socket.io/ https://apiary.io/ https://keen.io/
Either way, it's probably only 20 bucks so you might as well grab it. I missed the boat for the .io domain and now am regretting it :(
It took me awhile to find it to (I ran grep command to search all files for localhost). Looking through the code, it seems to have a lot of strange design choices. Hiding such an important variable in such a strange place being one of them.
Now that you are wiser, I would suggest the official tutorial (http://socket.io/get-started/chat/). It is minimalistic and a lot easier to follow.
I actually modified OpenTwitchPlays, added in some timing functions and did some stuff to stop my start9 spam issue.
But I would like to eventually move away from OTP, and IRC based chat control too.
In my spare time, I have been doing research with websockets and trying to find a new way to send control to the emulator via LUA.
Imagine being able to directly enter commands to change pokemon or choose moves or navigate menus by typing the menu name, or clicking on things on the emulated game stream.
!set slot1 pikachu - or dragging the mon around on an HTML5 loadout screen, then appending the changes in realtime by modifying the game's ram.
!tackle - or clicking on the words tackle on screen
!fly to pallet town - or clicking the location on the map
!release flareon - or clicking release
!buy 100 ultra ball
etc.
My final goal is to have a hybrid of PBR and Classic TPP. When in battle, there is a timer and you can vote on moves and the system chooses the highest voted one. Except not !a,!b,!c,!d - but the actual move names. When out of battle, you can use up/down/left/right to walk around - etc.
Its all possible by reading the game's ram, but this is some complex stuff - It may be a while till I figure this mess out.
This new control method would function similarly to how http://socket.computer does. I'm looking into reverse engineering its source code, as well as the systems running http://socket.io/demos/weplay/ , to see how they stream their game with virtually no delay.
with node.js :
setup your nodejs workflow and modules and hook it up with mongodb and look up some tutorials on how to use nodejs and node packages like express and mongoose. (1 day to set up everything maybe more if first time)
create a login passport.js system for authentication. (a few hours to a day depending on how much of you want to understand and scale) here is the workflow tutorial for it : https://scotch.io/tutorials/easy-node-authentication-setup-and-local
start adding database schemas for different rooms and users (a few hours - a few days depending on experience)
create your backbone.js models and views and database routes for user profiles and chat rooms with their own chat history stored in the db. create a collection for a list of chat rooms and logged users. (several days to make sure everything is perfect)
use socket.io to fetch all that data from the server and update the backbone view. (a few days) (you want to update chat room list, maybe that list will have rooms with each their own
the frontend will probably take much longer than then backend unless you decide to write some chat bots or add more advanced data.
here is a tutorial on how your backend/frontend workflow should look like https://www.youtube.com/watch?v=2BDGBJUtAmo this will get you started and then you can work from there to increase complexity
you can use this tutorial to figure out how to sync data between the backend and frontend in realtime http://socket.io/get-started/chat/
i would say it could take 1 - 3 weeks to make it worth using (and maybe even more if you have 0 experience with nodejs because you will be pausing and trying to understand the tutorials). Hello world nodejs websocket chat is not really applicable or scalable. You wanna make sure you set everything up so that you can add more functionality later on and have a good modular workflow if you want it to be successful later on.
This is a bit OT, but:
HTML5 localstorage won't help, because only the user that generated the data would be able to access it. The server needs this data so it can pass it on to the other clients.
You'd need a database to keep track of the session IDs on the server side, in conjunction with a (different) session cookie to track each individual client (in PHP, you can use $_SESSION
for this).
MongoDB is absolutely the wrong tool for this -- MongoDB isn't a relational database, and relating data is exactly what you're trying to do. If you're newish to databases, I recommend trying MySQL/MariaDB or SQLite.
If you're trying to send realtime data around to various clients, though, I'd look into ditching PHP and using something like socket.io in conjunction with a Nodejs server.
I couldn't find any specific details on how they implemented it, but my guess would be websockets. The button pushes would be sent from your phone to their server and then to your desktop. I'm not sure why they would go through all that effort and server load to implement a simple gallery, but I guess it is pretty cool.
I'd use socket.io and a simple static server to do something like that.
On public sites like the your example, you'd probably create a room for each desktop/phone pair.
The upside of full-stack JavaScript is that you're using full-stack JavaScript, one language for everything. For your example, that would mean being able to use one WebSocket implementation such as socket.io on both client and server.
Other than that, not much. If you're more familiar with one over another, use the one you like better.
WebSockets are the preferred method for what you're doing, WebRTC is a technology to connect two clients without server interaction.
When you have the time...
Learn socket.io/node.js
http://socket.io/get-started/chat/
This tutorial is very simple, straight forward, well explained, and quick to complete. If you have any understanding of javascript functions and events, this simple tutorial can open up a whole new world of possibilities.
Actually if you use socket.io (http://socket.io/#browser-support) your browser support is pretty amazing. It falls back to Flash on unsupported browsers - you don't need to do anything.
I would definitely suggest node + socket.io for this project.
I absolutely love working with Angular. I'm using it right now on a project and it's so fast and flexible. Combining Angular with websockets (I'm using socket.io for that) has so far produced an unbelievably fast and responsive web application.
I'm eager to see how Angular 2.0 turns out. The list of improvements looks great!
I second this - side projects are important. As a self-taught developer, I've never been able to learn new things unless I've presented myself a purpose to utilize what I'm learning.
In the pursuit of building a project using something you want to learn, you'll encounter many pitfalls and issues that are rarely covered in the "hello world" introductions. Because the project is your own and you have an ending point in mind, you'll want to solve the problems you run into.
For example, when I wanted to learn http://socket.io/ I immediately focused on building an in-browser chat client. I kept building upon it, and building upon it, adding features and doing things the way I really wanted. I ran into many pitfalls, learned many limitations, and reinvented the wheel many times, but in the end I had a working use and I learned a lot in the process.
Seems like you found some good resources, but yeah - it's pretty easy to add socket.io on top of other stuff. Specifically you want to look at the express section on the socket.io website:
For an example of this, check out this little template thingy that uses chat with socket.io with express:
https://github.com/MicrosoftWebMatrix/ExpressStarter
Hope this helps!
Short answer, use jquery ajax. It is the simplest solution for what you want to do. Just make sure your php and mysql is optimized to provide fast responses. You can also use node.js with socket.io but that's up to you. i have used both and always seem to come back to Jquery. backbone.js, underscore.js, require.js, mustache.js are completely unrelated to what you want to do.
P.S. I just looked at some code of mine from a couple of years back where I used XMLHttpRequest, and oh god I fucking hated those days!
For me the most interesting part thing is Socket.io. It has been ported to other languages (Erlang, Perl, Ruby, Python, Go, ...) which is awesome. They also have a list of companies and projects using Node
I played with it and it really has a nice list of great modules for modern web development. I am really not a JavaScript fan myself, but I am exploring node.js right now and it is really nice. They have a lot of activity going on, so you have a lot of modules despite, while not being outdated. Something that it very different from the early days of Python or Ruby. I guess it's because everything is focused around web development. I also have been afraid that there would be a lot of bad developers, because... well, I thought there would be lots of people who don't really know how to create serious stuff and just liked the fact that they don't need both JavaScript and PHP/Perl/Python/whatever. The main thing I dislike about JavaScript is the language itself. It's simply not my language, although I like the fact I can use Joose for OO.
You could use Socket.IO which is an abstraction layer that uses a mixture of different techniques to provide sockets (mainly Flash for the time being, until true websockets are feasible again). You can build your game client in JS, and there are server backends for Node.js, Java, Rack (Ruby) and Go.
I'm developing something similar (for about a year now, while learning) and you'll definitely have to use websockets. Thing is you need:
Check the http://socket.io/get-started/ library—much easier than pure WebSockets—on how to implement that... it's a journey to get it to work but once it does it'll open a lot of doors :)
Good luck!
Subscriptions aren’t tied to WebSockets, you can use any transport such as HTTP. Socket.io is a hybrid which can do both WebSocket and HTTP. You can even do GraphQL over Socket.io. I actually built a convenience wrapper for easily doing GraphQL over Socket.it 😄 https://github.com/n1ru4l/graphql-live-query/tree/main/packages/socket-io-graphql-server
If you want to reduce GraphQL payload overhead look into persisted GraphQL operations (search term: "persisted queries").
As you said for most smaller applications all those things would be over kill.
You can do this with any general purpose programming language that supports sockets but it can be very hard depending on technology. If you want to develop web app then I suggest to look into javascript api for sockets You can also do this hard way and write your own sockets in C. To be honest It's not that hard to make chat app.
Hi Redditors,
I’m Aurelien, one of the founders of Strapi! This is great news for the project and our amazing community!
Solomon Hykes (Founder of Docker), Guillermo Rauch (Founder of Cloudup, Socket.io, Next.js, and Zeit.co) and Eli Collins (Ex-CTO at Cloudera) participated in the round.
It will help deliver on our vision of making content accessible to any platform while offering a fully open-source, JavaScript-based, community-powered and 100% customizable Headless CMS which is entirely free for developers.
Happy to answer any of your questions!
thanks for your replay i will testing your code after back to my home and do you know why my code was working ok before converting my connection from http socket.io to https secure connection but after converting i started to get this problem ? do you have any idea why ?
Solution :
```
// server.ts
import * as socketIO from 'socket.io';
import BaseRouter from './routes/Base';
const server = createServer(app);
const io = socketIO.listen(server);
const baseRouter = BaseRouter(io);
app.use(baseRouter.path, baseRouter.router)
// BaseRouter.ts
import { Router } from 'express';
export const BaseRouter = (io) => {
// Init router and path
const router = Router();
const path = '/ChowApi';
// Add sub-routes
const customerRouter = CustomerRouter(io);
router.use(customerRouter.path, customerRouter.router);
return {
router,
path
};
}
export default BaseRouter;
// Customer.ts
const CustomerRouter = (io) => {
// Init router and path
const router = Router();
const path = '/customers';
return {
router,
path
}
};
export default CustomerRouter;
```
It kind of depends on what YOU want. If you want a chat app that lets users come back to chatrooms and see previous conversations then yes you need to store it in a DB.
This can all be done with node.js, socket.io, and mongodb. Plus your front end framework of course.
They even have an example on socket.io's website linked here
Try socket.io, they have android chat demo. I don't know details about the project, but keeping the connection with the server is not a good pattern, it's better to use FCM/GCM in most of cases, but maybe your case is different.
In general, I'd recommend not to implement everything yourself but use existing libraries. It's easier to develop, it's more reliable and it'll work faster.
I don't deal with much node, but what it sounds like you want might be something like socket.io http://socket.io/get-started/chat/. They have a few examples and show a bunch starting from a expressJS start which might be ideal for you also.
A bunch of games use this, and you can also use it to push things from the server to client if needed. You didn't talk too much about the client, but socket.io is well supported and many languages have libraries for it to.
Hey.
You can do this quite easily with socket.io.
http://socket.io/blog/native-socket-io-and-android/
If you need a server, go get one on AWS. You can get free tier and follow tutorial on how to deploy a node app. Even then a small client server will only run you a few bucks a month, depending on usage and size. You can stand up a node js app that also runs socket.io.
Thanks. I looked a tornado and looks a lot like socket.io (http://socket.io/) which I used for a simple node.js server to pass around gps data of all connected devices, while at the same time checking if someone was standing on a certain gps location. One final question for now, do is there chance you have a (few) source(s) to learn tornado, a tutorial or something like that.
If you balk at that, theres not much anyone can do. A lot of programming is struggling till you achieve your goal.
Just dig in, be confused for a while. The code you already wrote indicates you already know enough to get started.
I've used http://socket.io/ to update based on api calls made by anyone. Essentially the way this would work would be user submits a comment, socket.io sees the api call, and updates the comment stream for everyone.
When it comes to JS, many tutorials are pretty bad, and you'll be left confused and no wiser than when you started, so try to be discriminative. Have a look at some structured courses/books. I've heard good things about codeacademy, but haven't tried it myself. Also get your hand on a good book.
I do, however, recommend socket.io's tutorial: http://socket.io/get-started/chat/
Why not integrate the name choice process into the initial signup? Just show the prompt for username right after the user authenticates with openid, and if he choses not to, don't store his info into DB and treat all the nexst openid attempts as the first one, untill the person choses a (valid) username.
Try to skip the AJAX part and use websockets ( http://socket.io/ ) it it matches your userbase ( http://caniuse.com/#feat=websockets can't find socket.io support table )
The arguments the server calls the callback with will be sent to that client's function, yes. Every emit can essentially have its own personal response either way (server to client or client to server.)
> ...I'm now using socket.io over any sort of rest API for most purposes...
If it's as you say, then you'll likely benefit a lot with this approach, as it can be an easy drop-in. Socket.IO's website is down, but I'll copy and paste the specific part of their documentation, good luck!.. I'd enjoy hearing how its helped you and your project!
> # Sending and getting data (acknowledgements)
> chapter from Socket.IO's docs - down as of now
> Sometimes, you might want to get a callback when the client confirmed the message reception.
> To do this, simply pass a function as the last parameter of .send or .emit. What’s more, when you use .emit, the acknowledgement is done by you, which means you can also pass data along:
> Server (app.js)
> var io = require('socket.io')(80);
> io.on('connection', function (socket) {
> socket.on('ferret', function (name, fn) {
> fn('woot');
> });
> });
> Client (index.html)
> <script>
> var socket = io(); // TIP: io() with no args does auto-discovery
> socket.on('connect', function () { // TIP: you can avoid listening on connect
and listen on events directly too!
> socket.emit('ferret', 'tobi', function (data) {
> console.log(data); // data will be 'woot'
> });
> });
> </script>
Make sure nginx is configured for sticky sessions.
Not sure if you've seen the docs on the socket.io site about this: http://socket.io/docs/using-multiple-nodes/ but it should detail what you need
Has anyone used socket.io to build chat in an app? Is it scalable ? What are the issues faced with using it? Is it necessary to use it with node.js? Anything else that one should know when building chat using socket.io? Also what else can it be used for?
You should make a global account progression (this would need a login and register functionality), like getting new fish skins and stuff
Also, this is not an idea but you could try to implement http://socket.io/ instead of xhr requests. More speed and less server load!
Don't get toooo overwhelmed, need to walk before you can run! :)
Look into WebSockets ~ something like socket.io has tiered fallback mechanisms to use the fastest protocol available.
JavaScript would be good for the frontend. For the backend NodeJS actually has a very nice library called Socket.io for quick/easy realtime server/client communication. Check out how small their chatserver is. I got a player to player chess game going in a weekend.
For accessibility on multiple devices, check out Bootstrap for CSS, it's built for cross-platfom development even if it has a distinctive style it'll get you going quickly. After that you can theme it all you want.
Cheers!
socketio is pretty good with doing websocket communications. If you could use nodejs (javascript) on the server you can throw together a chat server in about an hour. It's pretty much emit("mytag", data)
and on("mytag", function(data){})
.
I know there is a C# client, so you might be able to hook them both up to the same server and have it work just like the chat app.
Cheers!
The browser support is still a bit shoddy for mobile, and are other problems with client support besides the browser. According to socket.io "at least 3 personal security applications block WebSocket traffic" and "Many corporate proxies block WebSocket traffic".
You would want to keep the socket server on the same port (80), but use a different domain. A socket.io server will handle the http and ws requests for that port/domain, since it needs to handle long polling over http and the socket connection.
If you open up the socket.io demo and then open the developer tools > network tab in your browser, you can see that they use a sub domain (chat.socket.io) for the socket server.
Re: connecting PHP to your socket server, there is a cool free Laracasts video here about how that works in Laravel.
Looks very cool, I'll definitely be using this the next time I need to write a CC script!
2 dev-y side notes:
Since you're already using Node.js, I would suggest using socket.io for a super easy-to-use, well documented solution for WebSockets.
Is this open source? I'd love to have a peak at the source code behind this.
There is no server in javascript. It runs only on the client.
You need to write a server with WebAPI, Java or Node.js. These will expose methods your client can call.
A different client will have to call them aswell.
Maybe this is a starting point for you:
Layer + Parse. A good solution but will cost you for the services.
If you want to write the real-time server code yourself look into using Socket.IO
I know this is an old (relatively) post. However, my suggestion to you is to look into specific things that you will need and try to adapt them to your project.
What I mean by this is to break it down into smaller questions.
For instance: What technology could I use to update any data in real time?
A simple answer is something like socket.io.
For an example of what I mean, think about what actually makes up a game.
Games in a simple form are mostly just data stored in objects which are then rendered on a screen depending on x,y,z.
players.player1.position = { x: 600, y: 256 }
You can use this, plus some movement and rendering code and socket.io to make a game where one person can see another person move around in real time.
If you are unclear about anything I've just said then I suggest that you try to look at more basic examples of game development and try to break it down to base requirements. If you like, I can point you toward some articles to help with particular areas - though I'm not sure what you're in specific need of. I'm only assuming that you are a beginner because the question you have asked is not focused. If I'm wrong, then please disregard what I've said.
If you know javascript/willing to learn it & want to use your own backend then you could try http://socket.io/
I know of other services along the lines of baas for websocket-based servers but their pricing is so silly that I won't even refer you to them.
The other posters have given some good feedback. This link may help you in regards to rooms and namespaces. You can determine who you want joining particular rooms, and choose to emit messages to specific rooms.
Yes. I used SIOSocket for this exact usage. SIOSocket can communicate with Socket.IO
Edit: it appears that Socket.IO now has their own iOS client written in swift.
Nice thing about Node is that it has a websocket library that's really easy to get started with: http://socket.io/
Simple start:
{ client_id: 42, x: 0, y: 0 }
for them to spawn the cursor on their screen.mousemove
event, emit the cursor's x and y coords through the socket to the server.{ client_id: 42, x: 33, y: 68 }
to all client sockets, and each client will draw that cursor at those coords.I am a CS student as well (actually in High School so I really don't know what I'm doing). I am REALLY bad at design and so that is where I struggle the most on.
The functionality for Chromecast apps is documented pretty well here. Depending on the game, it shouldn't require that many HTML5 specific features (maybe canvas), and the biggest part would be the JS. I would say the best way to learn things is doing projects. For example, after doing a project with socket.io, conveniently I now understand the communication between the sender and receiver apps because it is very similar.
A thing to note is that the Chromecast is pretty slow/choppy with animations (even with CSS only animations), so it would be best to keep them to a minimum.
You have probably already seen it but a new Game Manager API was released recently. It provides a ton of features to get some of the tedious things with the communications of games out of the way quickly. I was not very far in my project (school took up my time) so I will be implementing the API in my project.
Good luck!
You clone has an amazing interface but the data retrieve would be so slow. You should try by sending data in more sockets and binary:
http://socket.io/blog/introducing-socket-io-1-0/#binary
If you try to send all players will not work correctly, by using more than one socket you can improve a better and faster data transmission
While I've never used Instagram's API, Socket.IO (http://socket.io/) is good for bi-directional communication, and I imagine it could be tweaked to work well. If you're looking for a pure PHP implementation I've heard good things about Ratchet (http://socketo.me/) but have no first hand experience.
There are two options that come to mind, though I haven't tried either but they are on a todo list for me. So this may not work, but just my off-hand ideas on the subject.
Use some form of sockets, either with Ratchet or something built with Socket.io. When a page is loaded, you have a JS file that connects them to the socket service and that handles pushing the notifications.
Personally I've been thinking of having a Socket.io service on it's own server, something like a $5 droplet from Digital Ocean. Then use that to handle push notifications for a website in a similar implementation that you described. Right now it's just an idea, so I really would have to test it out to even find if it would work.
Simply join the socket(s) to a specific room and then publish to that room.
subscribe...
io.on('connection', function(socket){ socket.join('some room'); });
and publish...
io.to('some room').emit('some event')
http://socket.io/docs/rooms-and-namespaces/
you can also send directly to a socket by its id.
Follow this : http://socket.io/get-started/chat/
Once you figure this out you will be able to send any information you like from the client to the server and back. So, instead of a chat message, like in the example, you can just send the positions and other data you need to draw the canvas.
For hosting you will want a VPS (virtual private server) that you can install node on (or get a server pre-installed with node, many vps hosts offer something like this). Digital ocean has really nice guides, and I think it would be worth your time to figure this out : https://www.digitalocean.com/community/tutorials/how-to-install-express-a-node-js-framework-and-set-up-socket-io-on-a-vps...
No it doesn't. The socket.io website even says this - see here. You have to use the sticky-session module.
Not sure why he didn't mention sticky-session, though.
I wrote a very veeeeerry simple realtime chat room using angularjs for the front end and iojs + socket.io on the backend, and it only took less than 150 lines of my own code (most of it is html/angular boilerplate), so it would be very easy to do entirely in javascript.
I did a quick google search and socket.io even has a tutorial that holds your hand every step of the way.
Edit: I just checked the project, the angular code was 17 lines, the iojs server was 22 lines, and the html was 20 lines so I way overestimated how much it took to write (granted, the heavy lifting of sending messages etc is done by socket.io). The chat app basically allows you to enter a name and a message and send it to everyone else who connected to the server (as I mentioned, very basic) so it will definitely up the work needed if you want private rooms and user registration and all those other fancy features, but a very realistic project for a highschooler who only knows Javascript. (I would argue that programming knowledge is transferable to any language but that's another discussion)
your instantiation of 'io' is a little different from the socket.io docs for express. http://socket.io/docs/
express 3/4
var server = require('http').Server(app); var io = require('socket.io')(server);
express
var app = require('express').createServer(); var io = require('socket.io')(app);
Socket.io was recently announced for Android. I've never used it personally and so cannot vouch for it, however the demo app used in the announcement is a chat application.
I have found this http://socket.io/ > Socket.IO enables real-time bidirectional event-based communication. It works on every platform, browser or device, focusing equally on reliability and speed.
This looks really good; I don't need any of the crazy features just an event based system to push\pull and update..