this is part of code I am using to send apns.
Options = case Password of
undefined ->
[{certfile, Cert}, {keyfile, Keyfile}, {mode, binary}];
_ ->
[{certfile, Cert}, {keyfile, Keyfile}, {password, Password}, {mode, binary}]
end,
case ssl:connect(Address, Port, Options, ?Timeout) of
{ok, Socket} ->
PayloadBin = list_to_binary(Payload),
PayloadLength = size(PayloadBin),
TokenNum = erlang:binary_to_integer(Token, 16),
TokenBin = <<TokenNum:32/integer-unit:8>>,
Packet = <<
0:8,
32:16/big,
TokenBin/binary,
PayloadLength:16/big,
PayloadBin/binary
>>,
ssl:send(Socket, Packet),
ssl:close(Socket),
?DEBUG("mod_apns: Successfully sent payload to the APNS server", []),
ok;
{error, Reason} ->
?ERROR_MSG("mod_apns: Unable to connect:~p to the APNS server ~p: ~p", [Options, Address, Reason]),
Reason
end
But I get this error:
Unable to connect:[{certfile,<<"/etc/certificates/myCer.pem">>},{keyfile,<<"/etc/certificates/myKey.pem">>},{mode,binary}] to the APNS server <<"gateway.push.apple.com">>: {options,{socket_options,[{mode,binary}]}}
This is an ejabberd module and same code works in ejabberd 17.04 but not in 17.06.
Certificates and keys are valid and as I said I can get apns using same erlang module with older version of ejabberd.
I am new to erlang and I don't understand the error message ({options,{socket_options,[{mode,binary}]}})
Any help is appreciated.
The problem was I was sending binary instead of list:
mod_opt_type(address) -> fun binary_to_list/1;
mod_opt_type(port) -> fun(I) when is_integer(I) -> I end;
mod_opt_type(certfile) -> fun binary_to_list/1;
mod_opt_type(keyfile) -> fun binary_to_list/1;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.