Published on InterSystems Developer Community (https://community.intersystems.com)

Home > Cache Socket Client / Java Server

Question
Sorin Petrescu · Mar 8, 2021

Cache Socket Client / Java Server

Hi,

I have to create to a web socket client, but I'm unable to read any data from the server, after flushing the buffer. I have no access to the server, only two examples for the client, one in java and the other one in php:

java example:

socket = new Socket("192.168.0.1", 2003);

DataOutputStream out = new DataOutputStream(socket.getOutputStream());

out.writeUTF("aPassword");

out.writeInt(websiteId);

out.flush();

DataInputStream in = new DataInputStream(socket.getInputStream());

int orderId = in.readInt();

in.close();
out.close();
socket.close();

php:

$this->socket = socket_create(AF_INET, SOCK_STREAM, 0);

$this->writeStr($password);

$this->writeInt($id);

and the write functions are:

public function writeInt($value){
        $value = intval($value);
        return $this->write(pack('N', $value));
    }

public function writeStr($str){
        if (is_null($str))
            $str = 'null';
        $str = strval($str);
        $utfString = utf8_encode($str);
        $length = strlen($utfString);
        return $this->write(pack('n', $length).$utfString);
    }

The client I'm creating:

#dim sock As %IO.Socket = ##class(%IO.Socket).%New()
  
set id=57
set host = "89.73.132.83" set port = 2021
set password="1...5"

set sock.TranslationTable="UTF8"

set sockedOpened = sock.Open(host,port,-1)

do sock.Write(password, 0, .sc)
do sock.Write($$bl(57)_57, 0, .sc)
do sock.Flush(.sc)
set res=sock.ReadAny(12345, -1, .sc)

The socket opens successfully, I suppose there is a problem with the write command.

Any help would be appreciated.

#API #Caché
Product version: Caché 2015.1
$ZV: Cache for Windows (x86-64) 2015.2 (Build 664U) Fri Jul 10 2015 12:12:10 EDT

Source URL:https://community.intersystems.com/post/cache-socket-client-java-server