my UDP Server program halts from newsock.receivefrom()...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Rutvi Trivedi

    my UDP Server program halts from newsock.receivefrom()...

    I am trying to create a connection between Rabbit Controller and C# application using UDP.

    Rabbit as a client and GUI as a server.

    But my GUI App. goes into permanent waiting mode when it reaches newsock.receive from(data, ref Remote) line.

    I am not able to figure out the problem here because at controller side it shows that its sending data frequently after particular period of time.

    I have increased the buffer size in GUI App.

    Rabbit IP Address : 192.168.1.80
    Rabbit NetMask : 255.255.255.0
    Computer IP Address : 192.168.1.3
    NetMask : 255.255.255.0
    and gateway for both is 192.168.1.1

    Any kind of help is appreciated.

    Thanks
    Ruts
  • Airslash
    New Member
    • Nov 2007
    • 221

    #2
    Can you show me the code please where you call the receiveFrom method?

    I'm guessing you supplied an endpoint that's not holding the correct information. When you supply an endpoint in the ReceiveFrom method, only packets from that endpoint are handled.
    Since the function is a blocking call, you could end up blocking indefinitly if you specify the wrong endpoint.

    Comment

    • Rutvi Trivedi

      #3
      Hi

      Thanks for the reply.....Below is my code...

      ***C# as a server :-****

      Code:
      int recv;
      byte[] data = new byte[1024];
      
      IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050);
      
      Socket newsock = new Socket(AddressFamily.InterNetwork,                   SocketType.Dgram, ProtocolType.Udp);
      
      newsock.Bind(ipep);
      Console.WriteLine("Waiting for a client...");
      
      // I have also tried replacing 0 with 1234 (Port for Rabbit Controller)
      
      IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); 
      EndPoint Remote = (EndPoint)(sender);
      
      // from this function it goes into waiting mode.
      recv = newsock.ReceiveFrom(data, ref Remote); 
      
      Console.WriteLine("Message received from {0}:", Remote.ToString());
      
      Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
      Code:
      ***Rabbit Controller Code As a Client :-****
      
      static long sequence;
      auto char     buf[128];
      auto int     length, retval;
      
      #GLOBAL_INIT
      {
           sequence = 0;
      }
      
         printf("\nRutvi");
      
         buf = "Rutvi";
         length = strlen(buf) + 1;
      
          /* send the packet */
          retval = udp_send(&sock, buf, length);
      
         printf("\n\n %d",retval);
          if (retval < 0)
          {
              printf("Error sending datagram!  Closing and reopening socket...\n");
              
              sock_close(&sock);
      //LOCAL PORT = 1234
      //REMOTE_IP= "192.168.1.3"
      //REMOTE_PORT = 9050
      
              if(!udp_open(&sock, LOCAL_PORT, resolve(REMOTE_IP), REMOTE_PORT, NULL)) {
                  printf("udp_open failed!\n");
                  exit(0);
              }
          }
      
          tcp_tick(NULL);
          return 1;
      Last edited by Niheel; Oct 1 '10, 11:03 PM.

      Comment

      • Rutvi Trivedi

        #4
        Hi Thanks for the reply

        C# code is as below --- Using as a server

        Code:
        int recv;
                byte[] data = new byte[1024];
                IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050);
        
                Socket newsock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
        
                newsock.Bind(ipep);
                Console.WriteLine("Waiting for a client...");
        
                IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); // also used with 1234 (controller port)
                EndPoint Remote = (EndPoint)(sender);
        
                // from this function it goes into waiting mode.
                recv = newsock.ReceiveFrom(data, ref Remote); 
        
                Console.WriteLine("Message received from {0}:", Remote.ToString());
                Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
        RABBIT CONTROLLER CODE ....Working as a client

        Code:
        static long sequence;
            auto char     buf[128];
            auto int     length, retval;
        
            #GLOBAL_INIT
            {
                sequence = 0;
            }
        
           
           printf("\nRutvi");
        
           buf = "Rutvi";
           length = strlen(buf) + 1;
        
            /* send the packet */
            retval = udp_send(&sock, buf, length);
        
           printf("\n\n %d",retval);
            if (retval < 0)
            {
                printf("Error sending datagram!  Closing and reopening socket...\n");
                        sock_close(&sock);
                if(!udp_open(&sock, LOCAL_PORT, resolve(REMOTE_IP), REMOTE_PORT, NULL)) {
                    printf("udp_open failed!\n");
                    exit(0);
                }
            }
        
            tcp_tick(NULL);
            return 1;
        Last edited by Niheel; Oct 1 '10, 11:02 PM.

        Comment

        • Airslash
          New Member
          • Nov 2007
          • 221

          #5
          Your server code looks fine to me. You've followed the correct calling:
          - Create the socket
          - Bind the socket to a local endpoint, in your case any IP & Port
          - Receive the data from any source.

          I think the problem lies in your client. From the code I see there, I can't find the init for your socket. Perhaps something is wrong there.

          Comment

          • Rutvi Trivedi

            #6
            Hey

            Thanks very much for your reply.
            Init function at client side was called in main function....
            anyways I have solved the issue........
            Problem was with the security services set on my computer.....
            I have figured out that one..

            Once again thank u very much for your help.

            Ruts

            Comment

            Working...