Login Page - Create Account

Support Board


Date/Time: Fri, 20 Jul 2018 22:04:39 +0000



Post From: Trying to run JAVA demo program

[2017-12-02 17:41:59]
User905938 - Posts: 4
I think I have made it to the null Terminator, but it takes 30 seconds - 2 min to receive a response from the SC DTC server; when I send a baddly formed message after the login request it returns instantaneously. Can you please help me understand what I am missing. I am using Json response and I have the SC DTC server operating I think correctly, log attached at bottom.

Here is my sample socket code (package name removed), and I brought the messages into a String for simplicity.

=====================================================================================================
Java Class
=====================================================================================================

import java.io.*;
import java.net.*;
import java.util.Date;


public class SierraChartSocketClient {

public SierraChartSocketClient() {
String testServerName = "127.0.0.1";
int port = 11099;

try{
Socket socket = openSocket(testServerName, port);
socket.setTcpNoDelay(true);

String result = loginToSocketAndRequestData(socket);

System.out.println(result);

socket.close();
}catch(Exception e){
e.printStackTrace();
}

}

private String loginToSocketAndRequestData(Socket socket) throws Exception{
byte nullByte = 0x00;
String loginRequestString = "{\"Type\":1,\"Integer_1\":1,\"HeartbeatIntervalInSeconds\":60\", \"ClientName\": \"Sample Application\"}";

String marketDataRequestCL = "{\"Type\":101,\"RequestAction\":\"SUBSCRIBE\",\"SymbolID\":1,\"Symbol\":\"CLF8\", \"Exchange\":\"NYMEX\"}";
String heartBeat = "{\"Type\":3,\"CurrentDateTime \":\"" + (int) (System.currentTimeMillis() / 1000L) + "\" ";

try{
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));


BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(socket.getOutputStream());
System.out.println("Sending Over Login Request: " + new Date(System.currentTimeMillis()).toString());
bufferedOutputStream.write(loginRequestString.getBytes());
bufferedOutputStream.write(nullByte);
bufferedOutputStream.flush();


StringBuilder stringBuilder = new StringBuilder();
String str = bufferedReader.readLine();
System.out.println(str);
System.out.println("Received Login Response: " + new Date(System.currentTimeMillis()).toString());

bufferedOutputStream.write(heartBeat.getBytes());
bufferedOutputStream.flush();
System.out.println("Sending Heartbeat: " + new Date(System.currentTimeMillis()).toString());

bufferedOutputStream.write(marketDataRequestCL.getBytes("ISO-8859-1"));
bufferedOutputStream.write(nullByte);

while((str = bufferedReader.readLine()) != null){
stringBuilder.append(str + "\n");
System.out.println(str);
}


return null;
}catch (IOException e){
e.printStackTrace();
throw e;
}
}

private Socket openSocket(String server, int port) throws Exception{
Socket socket;

try{
InetAddress inteAddress = InetAddress.getByName(server);
SocketAddress socketAddress = new InetSocketAddress(inteAddress, port);

socket = new Socket();

int timeoutInMs = 45*1000; // 45 seconds
socket.connect(socketAddress, timeoutInMs);

return socket;

}catch (SocketTimeoutException e){
System.err.println("Timed out waiting for the socket.");
e.printStackTrace();
throw e;

}
}

public static void main(String[] args){
new SierraChartSocketClient();
}

}


=====================================================================================================
Java Console Output
=====================================================================================================
Sending Over Login Request: Sat Dec 02 10:38:07 MST 2017
{"Type":2,"ProtocolVersion":8,"Result":1,"Integer_1":0,"MarketDepthUpdatesBestBidAndAsk":0,"TradingIsSupported":0,"OCOOrdersSupported":0,"OrderCancelReplaceSupported":0,"SecurityDefinitionsSupported":1,"HistoricalPriceDataSupported":0,"ResubscribeWhenMarketDataFeedAvailable":0,"MarketDepthIsSupported":1,"OneHistoricalPriceDataRequestPerConnection":0,"BracketOrdersSupported":0,"UseIntegerPriceOrderMessages":0,"UsesMultiplePositionsPerSymbolAndTradeAccount":0,"MarketDataSupported":1,"ResultText":"Connected to SC DTC Protocol server. Service=rim","ReconnectAddress":"","ServerName":"SC DTC Server","SymbolExchangeDelimiter":""} {"Type":3,"NumDroppedMessages":0,"CurrentDateTime":0} {"Type":3,"NumDroppedMessages":0,"CurrentDateTime":0} {"Type":3,"NumDroppedMessages":0,"CurrentDateTime":0}
Received Login Response: Sat Dec 02 10:40:47 MST 2017
Sending Heartbeat: Sat Dec 02 10:40:47 MST 2017
null

Process finished with exit code 0

=====================================================================================================
Sierra Chart Log
=====================================================================================================
Software version: 1656 | 2017-12-02 10:38:03
Enabled for: Advanced Features. | 2017-12-02 10:38:03
Enabled for: Sierra Chart Historical Data Service. | 2017-12-02 10:38:03
Allow Support for Sierra Chart Data Feeds is enabled. | 2017-12-02 10:38:03
Current selected Data/Trading service: CQG FIX Trading | 2017-12-02 10:38:03
Chart Update Interval: 500 | 2017-12-02 10:38:03
Data/Trade Service Settings automatically set. | 2017-12-02 10:38:03
Time Zone: -07:00:00 (MST-07MDT+01,M3.2.0/02:00,M11.1.0/02:00) | 2017-12-02 10:38:03
2017-12-02 10:38:03 Local computer time | 2017-12-02 10:38:03
2017-12-02 17:38:03 Local computer time in UTC | 2017-12-02 10:38:03
2017-12-02 10:38:03 Local computer time in SC Time Zone | 2017-12-02 10:38:03
2017-12-02 17:30:04 Server time in UTC | 2017-12-02 10:38:03
Local computer UTC time and Server UTC time difference: 6 seconds. | 2017-12-02 10:38:03
Program path: C:\SierraChart\ | 2017-12-02 10:38:03
Data Files path: C:\SierraChart\Data\ | 2017-12-02 10:38:03
OS Version Number: 6.1 | 2017-12-02 10:38:03
Locale Setting: C | 2017-12-02 10:38:03

DTC Protocol server | Incoming connection from 127.0.0.1. | 2017-12-02 10:38:07
DTCServer (929) | Creating socket. | 2017-12-02 10:38:07
DTC client #59. 127.0.0.1 | Requested heartbeat interval: 40 | 2017-12-02 10:38:07
DTC client #59. Sample Application. 127.0.0.1 | Received logon request. | 2017-12-02 10:38:07
DTC client #59. Sample Application. 127.0.0.1 | Sent successful Logon response message to client. Username: . Result text: Connected to SC DTC Protocol server. Service=rim | 2017-12-02 10:38:07
DTC client #59. Sample Application. 127.0.0.1 | No heartbeat received after 1m 20s. Closing network socket. | 2017-12-02 10:40:48
DTCServer (929) | Initiating close of socket by core. | 2017-12-02 10:40:48
DTCServer (929) | Shutdown started. Waiting for graceful close. | 2017-12-02 10:40:48
DTCServer (929) | Socket gracefully closed by remote side. | 2017-12-02 10:40:48
DTCServer (929) | Closed. | 2017-12-02 10:40:48