How to make singal of socket for receiving data












0















I am working on yowsup and python messaging, I had made I socket receiver as a module and by the bot it's calling again and again as there is a socket binding, it gives an error that the address is already in use which is obvious, so how to make a python signal which call a function with certain parameters on incoming of data on socket



this is default module, which it receive message using @singal.command_received.connect it will call handle function.



from app.mac import mac, signals

'''
Signals this module listents to:
1. When a message is received (signals.command_received)
==========================================================
'''
@signals.command_received.connect
def handle(message):
if message.command == "hi":
print("Message from %s is %s"% (message.conversation,message))
hi(message)
h_send("hello", "917990253661")
elif message.command == "help":
help(message)

'''
Actual module code
==========================================================
'''
def hi(message):
who_name = message.who_name
answer = "Hi " + who_name
mac.send_message(answer, message.conversation)
def help(message):
answer = "I will help you"
mac.send_message(answer, message.conversation)


now i have made a socket code that receives data and according to that i want to call a function. which is bellow code.



from app.mac import mac, signals

'''
Signals this module listents to:
1. When a message is received (signals.command_received)
==========================================================
'''

import sqlite3, os
from threading import Thread
import pickle
from time import sleep
from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM, SOCK_STREAM

PORT_NUMBER = 3078
SIZE = 1024
hostName = gethostbyname('0.0.0.0')
mySocket = socket(AF_INET, SOCK_DGRAM)
mySocket.bind((hostName, PORT_NUMBER))

def handle():
try:
while True:
print("collecting.....")
(data, addr) = mySocket.recvfrom(SIZE)
print("do things")
pass
except Exception as mai:
print("Collect error:", mai)









share|improve this question





























    0















    I am working on yowsup and python messaging, I had made I socket receiver as a module and by the bot it's calling again and again as there is a socket binding, it gives an error that the address is already in use which is obvious, so how to make a python signal which call a function with certain parameters on incoming of data on socket



    this is default module, which it receive message using @singal.command_received.connect it will call handle function.



    from app.mac import mac, signals

    '''
    Signals this module listents to:
    1. When a message is received (signals.command_received)
    ==========================================================
    '''
    @signals.command_received.connect
    def handle(message):
    if message.command == "hi":
    print("Message from %s is %s"% (message.conversation,message))
    hi(message)
    h_send("hello", "917990253661")
    elif message.command == "help":
    help(message)

    '''
    Actual module code
    ==========================================================
    '''
    def hi(message):
    who_name = message.who_name
    answer = "Hi " + who_name
    mac.send_message(answer, message.conversation)
    def help(message):
    answer = "I will help you"
    mac.send_message(answer, message.conversation)


    now i have made a socket code that receives data and according to that i want to call a function. which is bellow code.



    from app.mac import mac, signals

    '''
    Signals this module listents to:
    1. When a message is received (signals.command_received)
    ==========================================================
    '''

    import sqlite3, os
    from threading import Thread
    import pickle
    from time import sleep
    from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM, SOCK_STREAM

    PORT_NUMBER = 3078
    SIZE = 1024
    hostName = gethostbyname('0.0.0.0')
    mySocket = socket(AF_INET, SOCK_DGRAM)
    mySocket.bind((hostName, PORT_NUMBER))

    def handle():
    try:
    while True:
    print("collecting.....")
    (data, addr) = mySocket.recvfrom(SIZE)
    print("do things")
    pass
    except Exception as mai:
    print("Collect error:", mai)









    share|improve this question



























      0












      0








      0








      I am working on yowsup and python messaging, I had made I socket receiver as a module and by the bot it's calling again and again as there is a socket binding, it gives an error that the address is already in use which is obvious, so how to make a python signal which call a function with certain parameters on incoming of data on socket



      this is default module, which it receive message using @singal.command_received.connect it will call handle function.



      from app.mac import mac, signals

      '''
      Signals this module listents to:
      1. When a message is received (signals.command_received)
      ==========================================================
      '''
      @signals.command_received.connect
      def handle(message):
      if message.command == "hi":
      print("Message from %s is %s"% (message.conversation,message))
      hi(message)
      h_send("hello", "917990253661")
      elif message.command == "help":
      help(message)

      '''
      Actual module code
      ==========================================================
      '''
      def hi(message):
      who_name = message.who_name
      answer = "Hi " + who_name
      mac.send_message(answer, message.conversation)
      def help(message):
      answer = "I will help you"
      mac.send_message(answer, message.conversation)


      now i have made a socket code that receives data and according to that i want to call a function. which is bellow code.



      from app.mac import mac, signals

      '''
      Signals this module listents to:
      1. When a message is received (signals.command_received)
      ==========================================================
      '''

      import sqlite3, os
      from threading import Thread
      import pickle
      from time import sleep
      from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM, SOCK_STREAM

      PORT_NUMBER = 3078
      SIZE = 1024
      hostName = gethostbyname('0.0.0.0')
      mySocket = socket(AF_INET, SOCK_DGRAM)
      mySocket.bind((hostName, PORT_NUMBER))

      def handle():
      try:
      while True:
      print("collecting.....")
      (data, addr) = mySocket.recvfrom(SIZE)
      print("do things")
      pass
      except Exception as mai:
      print("Collect error:", mai)









      share|improve this question
















      I am working on yowsup and python messaging, I had made I socket receiver as a module and by the bot it's calling again and again as there is a socket binding, it gives an error that the address is already in use which is obvious, so how to make a python signal which call a function with certain parameters on incoming of data on socket



      this is default module, which it receive message using @singal.command_received.connect it will call handle function.



      from app.mac import mac, signals

      '''
      Signals this module listents to:
      1. When a message is received (signals.command_received)
      ==========================================================
      '''
      @signals.command_received.connect
      def handle(message):
      if message.command == "hi":
      print("Message from %s is %s"% (message.conversation,message))
      hi(message)
      h_send("hello", "917990253661")
      elif message.command == "help":
      help(message)

      '''
      Actual module code
      ==========================================================
      '''
      def hi(message):
      who_name = message.who_name
      answer = "Hi " + who_name
      mac.send_message(answer, message.conversation)
      def help(message):
      answer = "I will help you"
      mac.send_message(answer, message.conversation)


      now i have made a socket code that receives data and according to that i want to call a function. which is bellow code.



      from app.mac import mac, signals

      '''
      Signals this module listents to:
      1. When a message is received (signals.command_received)
      ==========================================================
      '''

      import sqlite3, os
      from threading import Thread
      import pickle
      from time import sleep
      from socket import socket, gethostbyname, AF_INET, SOCK_DGRAM, SOCK_STREAM

      PORT_NUMBER = 3078
      SIZE = 1024
      hostName = gethostbyname('0.0.0.0')
      mySocket = socket(AF_INET, SOCK_DGRAM)
      mySocket.bind((hostName, PORT_NUMBER))

      def handle():
      try:
      while True:
      print("collecting.....")
      (data, addr) = mySocket.recvfrom(SIZE)
      print("do things")
      pass
      except Exception as mai:
      print("Collect error:", mai)






      python-3.x sockets serversocket asyncsocket yowsup






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 25 '18 at 5:05







      Nilanj

















      asked Nov 23 '18 at 7:21









      NilanjNilanj

      4010




      4010
























          0






          active

          oldest

          votes











          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%2f53442235%2fhow-to-make-singal-of-socket-for-receiving-data%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f53442235%2fhow-to-make-singal-of-socket-for-receiving-data%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

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          Origin of the phrase “under your belt”?