Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Trusted Contributor
cjonesy
Posts: 160
Registered: ‎09-13-2012
My Device: 9900
My Carrier: vodafone

Having to restart pb when connection fails

Hi all, 

 

I am trying to overcome a problem where when i try to receive a packet it doesn't return. I am discovering my server by sending a packet to 239.255.255.250 and then using the code below to find out the ip address when i receive a response.

 

My problem is I sometimes don't receive the response and recvfrom doesn't return and the only way to get back to having the app displayed on my device for debugging is to restart it. The server does actually send the packet but client doesn't receive it.

 

My code attempts to timeout when this happens but it doesn't.

 

Any help appreciated.

 

	 	   fd_set fds;

		 	  char *r_buffer = (char*)malloc(512); // Another buffer for receiving
		 	      struct sockaddr_in r_addr; // Where to store the remote address
		 	      socklen_t r_size = (socklen_t)sizeof(r_addr); // For recvfrom

		 	     fd_set readfds, masterfds;
		 	 	struct timeval timeout;

		 	     timeout.tv_sec = 10;                    /*set the timeout to 10 seconds*/
		 	       timeout.tv_usec = 0;
		 	      int response;

		 	       FD_ZERO(&masterfds);
		 	       FD_SET(sockfd, &masterfds);

		 	       memcpy(&readfds, &masterfds, sizeof(fd_set));

		 	       if (select(sockfd+1, &readfds, NULL, NULL, &timeout) < 0)
		 	       {
		 	         perror("on select");
		 	         exit(1);
		 	       }

		 	       if (FD_ISSET(sockfd, &readfds))
		 	       {
		 	    	   response = recvfrom(fd, r_buffer, 512, 0, (struct sockaddr*)&r_addr, &r_size); // Wait for packet until timeout

		 	       }

 

 

Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Having to restart pb when connection fails

This is might be a problem with IGMP protocol (judging by your IP). In order to receive multicast packets you have to IGMP-join the group and if IGMP does not refresh group's membership after some time (2-3 minutes) you are excluded from this group automatically. Check your logic of 'discovering server'

Please use plain text.
Trusted Contributor
cjonesy
Posts: 160
Registered: ‎09-13-2012
My Device: 9900
My Carrier: vodafone

Re: Having to restart pb when connection fails

Thanks Bgmot, not got back to you earlier on this as I lost 4 days worth of code last night and just needed to re code whilst fresh in memory - a nightmare.

 

I will look into what you said and reimplement my discovery process and your advice when other things have been redone.

 

Thanks.

 

C

Please use plain text.