How to integrate Django server with Nodejs SocketIO server












0















I'm finding a solution in integrate Client, Django and NodeJS. My task is building a server which user can message to each other. I have 2 solutions:




  1. From Client send request to Django server. Django server will create Message in Database and push a notification to NodeJS server(SocketIO), then Client will get change from NodeJs server. With this solution, I want to ask how can I push request socket from Django to Node?


enter image description here




  1. From Client send request to Socket server. Socket server will create Message in Database, then send it to Client. Is this solution good or bad? Does it need improvement?


enter image description here










share|improve this question





























    0















    I'm finding a solution in integrate Client, Django and NodeJS. My task is building a server which user can message to each other. I have 2 solutions:




    1. From Client send request to Django server. Django server will create Message in Database and push a notification to NodeJS server(SocketIO), then Client will get change from NodeJs server. With this solution, I want to ask how can I push request socket from Django to Node?


    enter image description here




    1. From Client send request to Socket server. Socket server will create Message in Database, then send it to Client. Is this solution good or bad? Does it need improvement?


    enter image description here










    share|improve this question



























      0












      0








      0








      I'm finding a solution in integrate Client, Django and NodeJS. My task is building a server which user can message to each other. I have 2 solutions:




      1. From Client send request to Django server. Django server will create Message in Database and push a notification to NodeJS server(SocketIO), then Client will get change from NodeJs server. With this solution, I want to ask how can I push request socket from Django to Node?


      enter image description here




      1. From Client send request to Socket server. Socket server will create Message in Database, then send it to Client. Is this solution good or bad? Does it need improvement?


      enter image description here










      share|improve this question
















      I'm finding a solution in integrate Client, Django and NodeJS. My task is building a server which user can message to each other. I have 2 solutions:




      1. From Client send request to Django server. Django server will create Message in Database and push a notification to NodeJS server(SocketIO), then Client will get change from NodeJs server. With this solution, I want to ask how can I push request socket from Django to Node?


      enter image description here




      1. From Client send request to Socket server. Socket server will create Message in Database, then send it to Client. Is this solution good or bad? Does it need improvement?


      enter image description here







      node.js django socket.io






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 20 at 23:35









      halfer

      14.5k758111




      14.5k758111










      asked Nov 23 '18 at 4:48









      KitKitKitKit

      8771228




      8771228
























          1 Answer
          1






          active

          oldest

          votes


















          2














          As you are using two server you will have to store socket_id against your user_id in the Database Redis key value.



          You will need :




          • Django Api Server

          • Redis or any other database

          • Node Socket Server


          For second solution :



          Django API logic for sending message will have to be implemented on Node Socket server.



          ex. user authentication, Checking target user, storing messages, finding user socket_id from database etc.



          For first solution :





          1. Use Redis Pub-Sub :
            From Django Server you can publish message on an event ex "send_message"



          { event_name: "send_message", target_user_id:"t_id",
          send_user_id:"u_id", target_socket_id:"t_sid", message:"Hello target"
          }




          On Node socket server you can Subscribe to that event and emit to specific socket_id




          io.to(data.target_socket_id).emit("event", data);





          1. You can create an endpoint on node server to receive the data from django server and pass
            Body parameters



          { event_name: "send_message", target_user_id:"t_id",
          send_user_id:"u_id", target_socket_id:"t_sid", message:"Hello target"
          }




          When node-server receives the API request you can use event emitter to emit the event



          process.emit(data.event_name,data)


          Inside Socket Connection File you can configure event listener



          process.on("send_message",(data)=>{
          io.to(data.target_socket_id).emit("event", data);
          });





          share|improve this answer
























          • Do you think the first or the second solution is good and easy for management? Or something else? Why, bro?

            – KitKit
            Nov 23 '18 at 7:50






          • 1





            @FeedGit I would prefer second solution for a simple chat application and use socket acknowledgement link and socket middle-ware link for authentication when socket connects.It will keep all the logic at one place.Hence easier to maintain.

            – Mukul Dev
            Nov 23 '18 at 8:34











          • Thank you very much Mukul. I'll try continuing with the Second.

            – KitKit
            Nov 23 '18 at 8:56











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440785%2fhow-to-integrate-django-server-with-nodejs-socketio-server%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          As you are using two server you will have to store socket_id against your user_id in the Database Redis key value.



          You will need :




          • Django Api Server

          • Redis or any other database

          • Node Socket Server


          For second solution :



          Django API logic for sending message will have to be implemented on Node Socket server.



          ex. user authentication, Checking target user, storing messages, finding user socket_id from database etc.



          For first solution :





          1. Use Redis Pub-Sub :
            From Django Server you can publish message on an event ex "send_message"



          { event_name: "send_message", target_user_id:"t_id",
          send_user_id:"u_id", target_socket_id:"t_sid", message:"Hello target"
          }




          On Node socket server you can Subscribe to that event and emit to specific socket_id




          io.to(data.target_socket_id).emit("event", data);





          1. You can create an endpoint on node server to receive the data from django server and pass
            Body parameters



          { event_name: "send_message", target_user_id:"t_id",
          send_user_id:"u_id", target_socket_id:"t_sid", message:"Hello target"
          }




          When node-server receives the API request you can use event emitter to emit the event



          process.emit(data.event_name,data)


          Inside Socket Connection File you can configure event listener



          process.on("send_message",(data)=>{
          io.to(data.target_socket_id).emit("event", data);
          });





          share|improve this answer
























          • Do you think the first or the second solution is good and easy for management? Or something else? Why, bro?

            – KitKit
            Nov 23 '18 at 7:50






          • 1





            @FeedGit I would prefer second solution for a simple chat application and use socket acknowledgement link and socket middle-ware link for authentication when socket connects.It will keep all the logic at one place.Hence easier to maintain.

            – Mukul Dev
            Nov 23 '18 at 8:34











          • Thank you very much Mukul. I'll try continuing with the Second.

            – KitKit
            Nov 23 '18 at 8:56
















          2














          As you are using two server you will have to store socket_id against your user_id in the Database Redis key value.



          You will need :




          • Django Api Server

          • Redis or any other database

          • Node Socket Server


          For second solution :



          Django API logic for sending message will have to be implemented on Node Socket server.



          ex. user authentication, Checking target user, storing messages, finding user socket_id from database etc.



          For first solution :





          1. Use Redis Pub-Sub :
            From Django Server you can publish message on an event ex "send_message"



          { event_name: "send_message", target_user_id:"t_id",
          send_user_id:"u_id", target_socket_id:"t_sid", message:"Hello target"
          }




          On Node socket server you can Subscribe to that event and emit to specific socket_id




          io.to(data.target_socket_id).emit("event", data);





          1. You can create an endpoint on node server to receive the data from django server and pass
            Body parameters



          { event_name: "send_message", target_user_id:"t_id",
          send_user_id:"u_id", target_socket_id:"t_sid", message:"Hello target"
          }




          When node-server receives the API request you can use event emitter to emit the event



          process.emit(data.event_name,data)


          Inside Socket Connection File you can configure event listener



          process.on("send_message",(data)=>{
          io.to(data.target_socket_id).emit("event", data);
          });





          share|improve this answer
























          • Do you think the first or the second solution is good and easy for management? Or something else? Why, bro?

            – KitKit
            Nov 23 '18 at 7:50






          • 1





            @FeedGit I would prefer second solution for a simple chat application and use socket acknowledgement link and socket middle-ware link for authentication when socket connects.It will keep all the logic at one place.Hence easier to maintain.

            – Mukul Dev
            Nov 23 '18 at 8:34











          • Thank you very much Mukul. I'll try continuing with the Second.

            – KitKit
            Nov 23 '18 at 8:56














          2












          2








          2







          As you are using two server you will have to store socket_id against your user_id in the Database Redis key value.



          You will need :




          • Django Api Server

          • Redis or any other database

          • Node Socket Server


          For second solution :



          Django API logic for sending message will have to be implemented on Node Socket server.



          ex. user authentication, Checking target user, storing messages, finding user socket_id from database etc.



          For first solution :





          1. Use Redis Pub-Sub :
            From Django Server you can publish message on an event ex "send_message"



          { event_name: "send_message", target_user_id:"t_id",
          send_user_id:"u_id", target_socket_id:"t_sid", message:"Hello target"
          }




          On Node socket server you can Subscribe to that event and emit to specific socket_id




          io.to(data.target_socket_id).emit("event", data);





          1. You can create an endpoint on node server to receive the data from django server and pass
            Body parameters



          { event_name: "send_message", target_user_id:"t_id",
          send_user_id:"u_id", target_socket_id:"t_sid", message:"Hello target"
          }




          When node-server receives the API request you can use event emitter to emit the event



          process.emit(data.event_name,data)


          Inside Socket Connection File you can configure event listener



          process.on("send_message",(data)=>{
          io.to(data.target_socket_id).emit("event", data);
          });





          share|improve this answer













          As you are using two server you will have to store socket_id against your user_id in the Database Redis key value.



          You will need :




          • Django Api Server

          • Redis or any other database

          • Node Socket Server


          For second solution :



          Django API logic for sending message will have to be implemented on Node Socket server.



          ex. user authentication, Checking target user, storing messages, finding user socket_id from database etc.



          For first solution :





          1. Use Redis Pub-Sub :
            From Django Server you can publish message on an event ex "send_message"



          { event_name: "send_message", target_user_id:"t_id",
          send_user_id:"u_id", target_socket_id:"t_sid", message:"Hello target"
          }




          On Node socket server you can Subscribe to that event and emit to specific socket_id




          io.to(data.target_socket_id).emit("event", data);





          1. You can create an endpoint on node server to receive the data from django server and pass
            Body parameters



          { event_name: "send_message", target_user_id:"t_id",
          send_user_id:"u_id", target_socket_id:"t_sid", message:"Hello target"
          }




          When node-server receives the API request you can use event emitter to emit the event



          process.emit(data.event_name,data)


          Inside Socket Connection File you can configure event listener



          process.on("send_message",(data)=>{
          io.to(data.target_socket_id).emit("event", data);
          });






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 7:32









          Mukul DevMukul Dev

          814




          814













          • Do you think the first or the second solution is good and easy for management? Or something else? Why, bro?

            – KitKit
            Nov 23 '18 at 7:50






          • 1





            @FeedGit I would prefer second solution for a simple chat application and use socket acknowledgement link and socket middle-ware link for authentication when socket connects.It will keep all the logic at one place.Hence easier to maintain.

            – Mukul Dev
            Nov 23 '18 at 8:34











          • Thank you very much Mukul. I'll try continuing with the Second.

            – KitKit
            Nov 23 '18 at 8:56



















          • Do you think the first or the second solution is good and easy for management? Or something else? Why, bro?

            – KitKit
            Nov 23 '18 at 7:50






          • 1





            @FeedGit I would prefer second solution for a simple chat application and use socket acknowledgement link and socket middle-ware link for authentication when socket connects.It will keep all the logic at one place.Hence easier to maintain.

            – Mukul Dev
            Nov 23 '18 at 8:34











          • Thank you very much Mukul. I'll try continuing with the Second.

            – KitKit
            Nov 23 '18 at 8:56

















          Do you think the first or the second solution is good and easy for management? Or something else? Why, bro?

          – KitKit
          Nov 23 '18 at 7:50





          Do you think the first or the second solution is good and easy for management? Or something else? Why, bro?

          – KitKit
          Nov 23 '18 at 7:50




          1




          1





          @FeedGit I would prefer second solution for a simple chat application and use socket acknowledgement link and socket middle-ware link for authentication when socket connects.It will keep all the logic at one place.Hence easier to maintain.

          – Mukul Dev
          Nov 23 '18 at 8:34





          @FeedGit I would prefer second solution for a simple chat application and use socket acknowledgement link and socket middle-ware link for authentication when socket connects.It will keep all the logic at one place.Hence easier to maintain.

          – Mukul Dev
          Nov 23 '18 at 8:34













          Thank you very much Mukul. I'll try continuing with the Second.

          – KitKit
          Nov 23 '18 at 8:56





          Thank you very much Mukul. I'll try continuing with the Second.

          – KitKit
          Nov 23 '18 at 8:56


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440785%2fhow-to-integrate-django-server-with-nodejs-socketio-server%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'