0

I do have the following code to connect to a JAVA Websocket Server:

$service_port = 10;
$address = 'localhost';

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP );
$result = socket_connect($socket, $address, $service_port);

$xml = '<?xml version="1.0" encoding="UTF-8"?><JAVADEMO><Question="Login-Anfrage"/></JAVADEMO>';
$msg_length = strlen( $xml );

$withLength = pack( "Na{$msg_length}", $msg_length, $xml );
$lngLen = strlen( $withLength );

$send_bytes = socket_write( $socket, $withLength, $lngLen );

while ($out = socket_read($socket, 2048)) {
    echo $out."<br />";
}

socket_close($socket);

This works perfect.

Now i have to connect to an SSL server. I have tried to change 'localhost' to 'ssl://localhost' or 'ssl://127.0.0.1' or 'ssl://192.168.0.1', .....

Nothings works. Anyone any idea how to connect to an SSL secured server?

EDIT: I was missing something: On the server side, there is no Apache running! It's a Java SSL server.

Sascha
  • 69
  • 1
  • 7
  • the default port for the ssl is 443 , if this server is using the default port you have to change the port number to 443 instead of 10 and keep the address like now – Amr Magdy Sep 27 '15 at 11:41
  • Hi Amry - i know... The SSL port for that server is changed to 10 - so the port is not the problem! I think i have to change the whole request, but i do not know how... – Sascha Sep 27 '15 at 11:45
  • i think we missed something, the SSL configuration is for apache correct ? so it is in http layer not socket layer, and apache manage the certificate exchange etc. so it is not managed by default at the lower level ( socket ). you can use RSA encryption or any encryption model to manage that, not sure if you can do with SSL certificate – Amr Magdy Sep 27 '15 at 11:51
  • On the server side, there is no apache running! It's an SSL secured Java Server! – Sascha Sep 27 '15 at 11:56
  • yes ok, and did you take care about enabling the ssl like mentioned http://stackoverflow.com/questions/1705856/socket-transport-ssl-in-php-not-enabled – Amr Magdy Sep 27 '15 at 12:02
  • Yes, on the client side it's both enabled. I think i have to rewrite the whole code with something like stream_socket_client, but i have no idea. – Sascha Sep 28 '15 at 08:02

0 Answers0