我想编写一个Scala客户端,通过与TLS的tcp连接来讨论专有协议.
基本上,我想从Scala中的Node.js重写以下代码:
var conn_options = {
host: endpoint,
port: port
};
tlsSocket = tls.connect(conn_options, function() {
if (tlsSocket.authorized) {
logger.info('Successfully established a connection');
// Now that the connection has been established, let's perform the handshake
// Identification frame:
// 1 | I | id_size | id
var idFrameTypeAndVersion = "1I";
var clientIdString = "foorbar";
var idDataBuffer = new Buffer(idFrameTypeAndVersion.length + 1 + clientIdString.length);
idDataBuffer.write(idFrameTypeAndVersion, 0 ,
idFrameTypeAndVersion.length);
idDataBuffer.writeUIntBE(clientIdString.length,
idFrameTypeAndVersion.length, 1);
idDataBuffer.write(clientIdString, idFrameTypeAndVersion.length + 1, clientIdString.length);
// Send the identification frame …Run Code Online (Sandbox Code Playgroud)