Login Page - Create Account

Support Board


Date/Time: Sat, 21 Apr 2018 03:37:24 +0000



Post From: Trying to run JAVA demo program

[2017-10-12 20:02:18]
User178540 - Posts: 8
Hello,

I have written a simple JAVA code using protoc, in order to connect via DTC and get market data.
But no reponse arrives to the program. BTW, is there any example test program I can use?

----------------------

public static void main(String argv[]) throws Exception {
    System.out.println("Starting...");
    
    String modifiedSentence;
    BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
    Socket clientSocket = new Socket("127.0.0.1", 11099);

    if (clientSocket.isConnected()) {
      System.out.println("Connected. ");
    }
    
    DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());

    // User DTC API
    MarketDataRequest request = MarketDataRequest.newBuilder()
                    .setRequestAction(RequestActionEnum.SUBSCRIBE)
                    .setSymbolID(1)
                    .setSymbol("GOOG")
                    .build();
    
    System.out.println(request.toString());
                    
    
    
    String sentence = request.toString();
    outToServer.writeBytes(sentence + '\n');

    BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
    sentence = inFromUser.readLine();
    modifiedSentence = inFromServer.readLine();
    System.out.println("FROM SERVER: " + modifiedSentence);
    
    Thread.sleep(300000);
    
    clientSocket.close();
  }
}