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:
set id=57
set host = "89.73.132.83" set port = 2021
set password="1...5"
set sock.TranslationTable="UTF8"
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.
InterSystems IRIS natively supports WebSockets protocol as a client (your case) and as a server.
Consider upgrading.
Are you saying there is no solution with Cache 2015?
Cache 2015 is a very old release. You should update to a latest version at least, preferably to InterSystems IRIS.
Mr. Lebedyuk,
I understand your worry. You can consider your responses not usefull as you don't know the whole context. I don't think you can appreciate the costs coming from updating.
in OEX there is a series of various Websocket Clients I produced:
The internal is just available in IRIS.
Half Externals (eg. CSP based, using JavaScript ) might fit also for Caché 2015 as for IRIS
check WebSocketClient CSP based
Thank you, Robert.
I read about your examples. My problem is more related to the write command. I do not know if there is a possibility in Cache to create the same function of the following:
JAVA (DataOutputStream->writeUTF)
Writes a string to the underlying output stream using modified UTF-8 encoding in a machine-independent manner.
First, two bytes are written to the output stream as if by the
writeShort
method giving the number of bytes to follow. This value is the number of bytes actually written out, not the length of the string. Following the length, each character of the string is output, in sequence, using the modified UTF-8 encoding for the character. If no exception is thrown, the counterwritten
is incremented by the total number of bytes written to the output stream. This will be at least two plus the length ofstr
, and at most two plus thrice the length ofstr
.or
PHP (pack function)
write(pack('n', $length).$utfString);
I'm not sure what the first 2 bytes are but $ZCVT(anystring,"O","UTF8") should do the conversion
and this works for strings up to ~3,6 MB with Long-String enabled in your installation
for $ZCVT: https://docs.intersystems.com/iris20201/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_fzconvert
UTF8 has to be set to the socket translation table:
Set sock.TranslationTable="UTF8"
and the solution in objectscript for the Java function:
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
out.writeUTF(str);
is the following:
Do sock.Write(str, 0, .sc)
setShort(num) {
Quit $Reverse($ZWChar(num))
}
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue