NetTalk Central

Author Topic: problem reaching Apple's Notification service (webservice)  (Read 3438 times)

joep

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • Email
problem reaching Apple's Notification service (webservice)
« on: September 12, 2013, 01:12:19 AM »
Hi There,

I 'am having trouble reaching the APNS (apple Notification Service).
I get following error:
"Connection failed to open NetError = -66 SSLError = 0 WinsockError = 0"
I'm not sure what this error means.
Is there somewhere a list with explanation of all NetError's and SSLError's?

This is my code, hope someone can help me:

!Stuur push bericht
!Init
apnsHost = 'gateway.sandbox.push.apple.com'
!apnsHost = '17.172.233.65'
apnsCert = 'certificaten\cert.pem'
apnsKey  = 'certificaten\key.pem'
apnsRoot = 'certificaten\AppleIncRootCertificate.pem'
apnsPort = '2195'
apnsUrl = apnsHost & ':' & apnsPort

unixDate = Today() - Deformat('19700101',@d12)
unixTime = (UnixDate * 86400) + Round(Clock()/100,1)

unixExpiry = st.LongToHex(unixTime + 86400) ! add 1 day
st.SetValue(unixExpiry)
st.FromHex()
apnsExpiry = st.GetValue()

Message('JulianDate=' & Today() & ' 01/01/1970=' & Deformat('19700101',@d12) & ' Time=' & Round(Clock()/100,1) & ' UnixDate=' & UnixDate &  ' unixTime=' & unixTime & ' unixExpiry=' & Clip(unixExpiry) & ' hex=' & apnsExpiry)

json = '{{"aps" : {{ "alert" : "Hallo mijn eerste push bericht", "badge" : 1, "sound" : "default" } }'
!json = '{{"aps" : {{ "alert" : "Hallo mijn eerste push bericht", "badge" : 1, "sound" : "default" } }'
!SETCLIPBOARD(json)
 
deviceToken = '0b9e08cdd8baa77rdes34s3gfhh4565ggh57uhf4543gbcfc38173' 
!PostString = Chr(0) & Chr(0) & Chr(32) & DeviceToken &  Chr(0) & Chr(Len(Clip(json))) & Clip(jSon)
PostString = Chr(1) & '1234' & apnsExpiry & Chr(32) & DeviceToken &  Chr(0) & Chr(Len(Clip(json))) & Clip(jSon)

net.CanUseProxy = 1           ! Can use a proxy
net.HeaderOnly = 0            ! We want the whole page
     
net.AsyncOpenUse = 1          ! Use AsyncOpen 12 seconds (recommended)
net.AsyncOpenTimeOut = 1200   ! Up to 12 seconds to connect
     
net.InActiveTimeout = 9000    ! Set IdleTimeout 90 seconds
net.ConnectionKeepAlive = 0

!        These settings would be required if you were talkig to a SOAP server that only did SSL.
Net.SSL = 1
net.SSLCertificateOptions.CertificateFile = apnsCert
net.SSLCertificateOptions.PrivateKeyFile = apnsKey
net.SSLCertificateOptions.CARootFile = apnsRoot    !'.\CaRoots.pem'
net.SSLCertificateOptions.DontVerifyRemoteCertificateCommonName = 1
net.SSLCertificateOptions.DontVerifyRemoteCertificateWithCARoot = 1
!        If https use a root cluster like '.\CA_Roots.pem'
 
         !net.AsyncOpenUse = 1
         !net.AsyncOpenTimeOut = 1200 ! 12 sec
         !net.InActiveTimeout  = 9000 ! 90 sec

net.ContentType = 'text/xml; charset=utf-8'
net.AcceptEncoding = ''
net.ContentLength = Len(Clip(PostString))

        ! Set the SOAPAction header to tell the web service which method to execute
        !net.customheader = 'SOAPAction: "http://www.egem.nl/StUF/sector/bg/0310/aoaLv01"'

SetCursor(Cursor:Wait)

net.Post(apnsUrl, PostString)
If net.Error
  Message ('Could not post the request to this web service. Error ' & net.Error & ': ' & net.InterpretError())
  SetCursor()
End

Regards Joep
Clarion 6,3
Nettalk 7,05

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: problem reaching Apple's Notification service (webservice)
« Reply #1 on: September 12, 2013, 03:13:16 AM »
Sounds like the URL. You may need to clip apnsHost. Regardless stick a debug point in after this line to check the value of apnsUrl

apnsUrl = apnsHost & ':' & apnsPort

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: problem reaching Apple's Notification service (webservice)
« Reply #2 on: September 12, 2013, 10:02:04 PM »
>> Is there somewhere a list with explanation of all NetError's and SSLError's?

Netall.Inc contains a list. including;
ERROR:SSLFailedToLoadPrivateKey       equate(-66)


Which I guess means that this file;
apnsKey  = 'certificaten\key.pem'
is either in the wrong place, or not the right format.
(you might want to put a full-pathname in - you're assuming the currentpath at this point, and that may not be true.)

cheers
Bruce

joep

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • Email
Re: problem reaching Apple's Notification service (webservice)
« Reply #3 on: October 01, 2013, 06:01:17 AM »
Thanks all.

I have got it working now.
The certificate was indeed the problem.
I tested it with openssl and after generating new certificates with the Apple Developers account I got response.

But what I really want now is to fire notifications in a batch sequence.

To do that I have created an procedure to process a file.
I included the netSimpleObject.

After the init of the netSimpleObject I do an Net.open.
And in the for each record activity embed I do the net.Send

But the connection is not open when I do the net.Send.

I used debugview to get behind the problem.
Actually the connection doesn't get open until the whole file is processed.
To be precice wrigth before the connection close embed.

Does anyone have a clue,why the connection is not open when I process the file?

Regards,
Joep

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: problem reaching Apple's Notification service (webservice)
« Reply #4 on: October 03, 2013, 02:10:01 AM »
Hi Joep,

you're thinking stncronously, and NetTalk is asyncronous. you may have more joy if you set the Open to be syncronous though.

netsimple.AsyncOpenUse = false

before the Open

cheers
Bruce

joep

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • Email
Re: problem reaching Apple's Notification service (webservice)
« Reply #5 on: October 04, 2013, 05:13:23 AM »
Hi Bruce,

Maybe it's not possible in an synchronous way.
These are some of the specifications for the Apple Notification Server :

General Requirements

As a provider you communicate with Apple Push Notification service over a binary interface. This interface is a high-speed, high-capacity interface for providers; it uses a streaming TCP socket design in conjunction with binary content. The binary interface is asynchronous

Although Debugview tells me the connection is succesfull, but I get no response:

NetSimple.Open - self._connection.mode=0 server=gateway.sandbox.push.apple.com port=2195
NetSimple(Client).Open - Attempting to connect to gateway.sandbox.push.apple.com on Port 2195
NetSimple(Client).Open - Will use InActive (Idle) Timeout (hs) = 9000
NetSimple(Client).Open - Connection opened on Socket = 648 SockID = 2
NetSimple.Send (Client Mode) - Sending Data to HostName = gateway.sandbox.push.apple.com OnSocket = 648 SockID = 2 Port = 2195 BinDataLen = 198
NetSimple.Send (Client Mode) - Sending Data to HostName = gateway.sandbox.push.apple.com OnSocket = 648 SockID = 2 Port = 2195 BinDataLen = 199
NetSimple.Send (Client Mode) - Sending Data to HostName = gateway.sandbox.push.apple.com OnSocket = 648 SockID = 2 Port = 2195 BinDataLen = 199
NetSimple.Send (Client Mode) - Sending Data to HostName = gateway.sandbox.push.apple.com OnSocket = 648 SockID = 2 Port = 2195 BinDataLen = 200
NetSimple.Close - Closing Client Socket = 648 SockID = 2 to Server = gateway.sandbox.push.apple.com Originally Connected to Port = 2195

I was also curious if  there's  a way to send a password along with a certificate?

Regards,
Joep

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: problem reaching Apple's Notification service (webservice)
« Reply #6 on: October 06, 2013, 11:00:23 PM »
Hi Joep,

There is a difference between asynchronous Opens and asynchronous transfers.Comms in NetTalk is always asynchronous, the Open can be force to be Synchronous.

your root problem is that you are using a Process procedure, which means that

>> And in the for each record activity embed I do the net.Send

since the Open is asyncronous (unless you use the flag I suggested) you'll therefore start sending before the port is open. If you let the open be syncronous, then you can send in the process like this - although of course the replies coming back will arrive at some point in the future.

and since you're using a Process procedure, the procedure has probably finished long before the replies have all arrived. So I'm guessing you're not gonna get (most of) the replies. Which may or may not be important to you. So the "lack of response" is very expected in the architecture you are using (although it's probable that the data did get delivered to the remote server.)

>> I was also curious if  there's  a way to send a password along with a certificate?

unfortunately the context of this question is missing, so it's impossible to answer. You can send anything you like, but I'm not sure what you mean by "with the certificate".

cheers
Bruce