Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing connection after getting response from apple #183

Open
GoogleCodeExporter opened this issue Apr 23, 2015 · 3 comments
Open

Closing connection after getting response from apple #183

GoogleCodeExporter opened this issue Apr 23, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1.push notitfication to list fo devices.(include an invalid token)


What is the expected output? 
readResponses(Socket socket) method in ResponsePacketReader closes the 
connection.
Before it reach the method the socket is not closed .
After reading the response connection is closed.


What do you see instead?
socket should be reusable.


What version of the product are you using? 
2.2

On what operating system?
Windows

Please provide any additional information below.
Is it possible to resuse the connection instead of closing the connection.
It may be closing the connection because 

/* Set socket timeout to avoid getting stuck on read() */
try {
    previousTimeout = socket.getSoTimeout();
    socket.setSoTimeout(TIMEOUT);
    } catch (Exception e) {
Why do we need to set 'TIMEOUT' which is 5 seconds.

I'm trying to send 5000 notitifcation on a connection. One reason or the other 
end up in  java.net.SocketException: Socket Closed

Original issue reported on code.google.com by mohamfbh...@gmail.com on 8 May 2013 at 3:18

@GoogleCodeExporter
Copy link
Author

The way the sockets are handled right now is a result of how APNS works.

Sending 5000 notifications shouldn't be a problem, and sockets opening/closing 
should be handled automatically by the library.  If you are experiencing 
exceptions, please provide the code you are using, as well as a copy of the log 
output for an attempt.

Original comment by sype...@gmail.com on 8 May 2013 at 8:58

@GoogleCodeExporter
Copy link
Author

Original comment by sype...@gmail.com on 8 May 2013 at 8:59

  • Changed state: Evaluating

@GoogleCodeExporter
Copy link
Author

Thank you for prompt reply.
In fact we need to push arround couple of millions notifications 
we start 400 threads(that sends 5000 messages) simaltaniously. (code given 
below) . One reson or the other when start the threads , ends up in timeout 
Exception.(sometimes)
it's throwing when tring to excute 

if (socketTimeout > 0)this.socket.setSoTimeout(socketTimeout); in 
PushNotificationManager.java ( protected void sendNotification() method)

It works , If I catch the exception and reinitialize connection.


However , my biggest worry is ;

Each thread will close the connection after sending 5000 messages .
If this exceptions thrown we cannot read the response from Apple.


public class PushBulkWorker implements Runnable {
    private static final Logger logger = LoggerFactory.getLogger(PushBulkWorker.class);

    List<String> tokens;
    String message;
    AppleNotificationServer server;
    int no;

    public PushBulkWorker(List<String> tokens, String message, AppleNotificationServer server,int no) {
    super();
    this.tokens = tokens;
    this.message = message;
    this.server = server;
    this.no=no;
}

    private void send() throws Exception {
        PushNotificationPayload payload = PushNotificationPayload.alert(message);
        PushedNotifications notifications;
        PushNotificationManager pushManager;
        notifications = new PushedNotifications();
        pushManager = new PushNotificationManager();
        pushManager.initializeConnection(server);
        pushManager.setEnhancedNotificationFormatEnabled(false);
        List deviceList = Devices.asDevices(tokens);
        notifications.setMaxRetained(deviceList.size());
        for(Iterator i$ = deviceList.iterator(); i$.hasNext();)
        {
            Device device = (Device)i$.next();
            try
            {
                BasicDevice.validateTokenFormat(device.getToken());
                PushedNotification notification = pushManager.sendNotification(device, payload, true);
                notifications.add(notification);
            }
            catch(InvalidDeviceTokenFormatException e)
            {
                notifications.add(new PushedNotification(device, payload, e));
            }
        }
        try
        {
            pushManager.stopConnection();
            System.out.print(" fin : "+no);
            //System.out.println("thred ---------------     "+no+" finished");
            //logger.info("thred ---------------     "+no+" finished");
        }catch(Exception e) 
        { 
            e.printStackTrace(); 
        }finally
        {
        }
    }


    public void run() {
        try {
            send();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}



Original comment by mohamfbh...@gmail.com on 9 May 2013 at 8:49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant