{"id":20042579,"url":"https://github.com/code4mk/now-socketio","last_synced_at":"2025-06-15T00:03:25.959Z","repository":{"id":104452483,"uuid":"149031005","full_name":"code4mk/now-socketio","owner":"code4mk","description":"💬 A short Journey of Socket.io","archived":false,"fork":false,"pushed_at":"2018-09-17T20:56:17.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-19T12:55:25.754Z","etag":null,"topics":["socket-io","socketio"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/code4mk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-09-16T19:59:16.000Z","updated_at":"2018-09-17T20:56:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"3b0fdd1d-41a8-4a32-9f00-220e6bc332c5","html_url":"https://github.com/code4mk/now-socketio","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"17dde86eb406754e2e5161a059bf6aa0549a8166"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code4mk%2Fnow-socketio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code4mk%2Fnow-socketio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code4mk%2Fnow-socketio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/code4mk%2Fnow-socketio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/code4mk","download_url":"https://codeload.github.com/code4mk/now-socketio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241470402,"owners_count":19968041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["socket-io","socketio"],"created_at":"2024-11-13T10:52:22.177Z","updated_at":"2025-03-02T07:17:56.026Z","avatar_url":"https://github.com/code4mk.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# now-socketio\nA short Journey of Socket.io\n\n### socketio Relationship\n\n![client images](https://cdn-images-1.medium.com/max/2000/1*Ju3JkhXr0Jrb_tAb0LiIhw.png)\n\n### server-side\n\n```js\nvar serverIO = require('socket.io')(9000);\n\nserverIO.on('connection', (socket) =\u003e {\n  // fetch\n  socket.on('message', (response) =\u003e {\n    console.log(response.name)\n   });\n   // sent\n   socket.emit('post', {\n     title: 'data server to cilent',\n     like: 100\n   })\n  socket.on('disconnect', () =\u003e { });\n});\n```\n\n### client-side\n\n```js\nvar socket = io('http://localhost:9000');\nsocket.on('connect', () =\u003e {\n  socket.send('hi');\n  //  sent\n  socket.emit('message',{\n    id: 1,\n    name: 'socket.io'\n  })\n  // fetch\n  socket.on('post', (response) =\u003e {\n    console.log(response.title)\n  });\n});\n```\n\n### emit cheetsheat\n\n![emit](https://cdn-images-1.medium.com/max/2000/1*1hAQzCAuZzhkBPtMpsN5KA.png)\n\n### emit\n\n```js\n// sending to sender-client only\nsocket.emit('message', \"this is a test\");\n\n// sending to all clients, include sender\nio.emit('message', \"this is a test\");\n\n// sending to all clients except sender\nsocket.broadcast.emit('message', \"this is a test\");\n\n// sending to all clients in 'game' room(channel) except sender\nsocket.broadcast.to('game').emit('message', 'nice game');\n\n// sending to all clients in 'game' room(channel), include sender\nio.in('game').emit('message', 'cool game');\n\n// sending to sender client, only if they are in 'game' room(channel)\nsocket.to('game').emit('message', 'enjoy the game');\n\n// sending to all clients in namespace 'myNamespace', include sender\nio.of('myNamespace').emit('message', 'gg');\n\n// sending to individual socketid (server-side)\nsocket.broadcast.to(socketid).emit('message', 'for your eyes only');\n\n// join to subscribe the socket to a given channel (server-side):\nsocket.join('some room');\n\n// then simply use to or in (they are the same) when broadcasting or emitting (server-side)\nio.to('some room').emit('some event'):\n\n// leave to unsubscribe the socket to a given channel (server-side)\nsocket.leave('some room');\n\n```\n\n\n\n### sources\n\n* [devdocs](http://devdocs.io/socketio/)\n* [room socket](https://gist.github.com/mostafa6765/482d28caa02f59f6da12d13ea907e856)\n* [room socket](https://gist.github.com/crtr0/2896891)\n\n* [mongo socket 1](https://www.youtube.com/watch?v=8Y6mWhcdSUM)\n* [mongo socket 2 / last](https://www.youtube.com/watch?v=hrRue5Rt6Is)\n\n\n* [chat.io](https://github.com/OmarElGabry/chat.io/blob/master/app/socket/index.js)\n\n* [angular](https://github.com/ShankyTiwari/Realtime-Private-Chat-using-AngularJs-Nodejs-and-Mysql)\n\n* [socketio redis](https://github.com/socketio/socket.io-redis)\n\n* [short journey socket medium](https://medium.com/code4mk-org/a-short-journey-of-socket-io-with-code4mk-86c9e198720e)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode4mk%2Fnow-socketio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcode4mk%2Fnow-socketio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcode4mk%2Fnow-socketio/lists"}