Login Page - Create Account

Support Board


Date/Time: Sat, 18 May 2024 12:27:22 +0000



Google Protocol Buffers not working

View Count: 1661

[2018-04-10 07:56:33]
User942837 - Posts: 108
Hi,

I am creating a client wrapper for DTC and managed to get it working on JSON messages. From one of your replies on this forum, you recommend to start with JSON and switch to Google Protocol Buffers. I have downloaded the most recent stable version 3.5.1 and generated code using the https://github.com/DTC-protocol/DTC/blob/master/DTCProtocol.3.proto file on github. This seems to be outdated as it is using DTC version 7 and not 8 (as per the following link https://dtcprotocol.org/DTC_Files/DTCProtocol.proto) but I am not sure if this is the problem.

I updated sierra server setting to use Google Protocol Buffers and made a Logon request which isn't working.

DTC Protocol server | Incoming connection from 127.0.0.1. | 2018-04-10 09:23:26
DTCServer (55) | Creating socket. | 2018-04-10 09:23:26
DTC client #6. 127.0.0.1 | No activity on network socket. Closing network socket. Bytes in receive buffer: 0 | 2018-04-10 09:23:47
DTCServer (55) | Initiating close of socket by core. | 2018-04-10 09:23:47
DTCServer (55) | Shutdown started. Waiting for graceful close. | 2018-04-10 09:23:47
DTCServer (55) | Close event error. Windows error code 10053: An established connection was aborted by the software in your host machine. | 2018-04-10 09:23:50 *
DTCServer (55) | Socket gracefully closed by remote side. | 2018-04-10 09:23:50
DTCServer (55) | Closed. | 2018-04-10 09:23:50

I am simply using the following code and sending bytes to socket.

LogonRequest lr = new LogonRequest();
lr.HeartbeatIntervalInSeconds = 5;
lr.ClientName = "Sample";
lr.TradeMode = TradeModeEnum.TradeModeDemo;
lr.HeartbeatIntervalInSeconds = 5;
byte[] loginRequestMsg = lr.ToByteArray();

Can you kindly let me know what am I doing wrong and the best way to proceed as I am stuck. I am using sierra 1702.

Thanks
[2018-04-10 17:54:23]
Sierra Chart Engineering - Posts: 104368
Definitely use this file:
https://dtcprotocol.org/DTC_Files/DTCProtocol.proto

We are removing the other one because it is not being kept up-to-date. And using the Google protocol buffer version 3 compiler, it can compile a version 2 protocol definition file.

This line indicates that Sierra Chart received zero bytes from your client:
DTC client #6. 127.0.0.1 | No activity on network socket. Closing network socket. Bytes in receive buffer: 0 | 2018-04-10 09:23:47

So it actually did not send any data to Sierra Chart.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2018-04-10 17:54:50
[2018-04-10 20:13:09]
User942837 - Posts: 108
the reason why I found the proto3 version is precisely because proto2 version it did not compile on proto3.

protoc.exe DTCProtocol.proto --csharp_out E:\
--csharp_out: DTCProtocol.proto: C# code generation only supports proto3 syntax

I am still stuck and there is no proto2 compiler for c#.
[2018-04-10 20:33:06]
Sierra Chart Engineering - Posts: 104368
OK we did not know that using C # requires protocol version 3. We will have to update that pprotocol definition file but that is not the reason for the issue.

In any case we will get the version 3 file out today or tomorrow.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2018-04-10 20:33:26
[2018-04-11 02:56:40]
Sierra Chart Engineering - Posts: 104368
Here is the protocol buffer file for the DTC Protocol that is compatible with the Google protocol buffer compiler version 3.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
attachmentDTCProtocol.3.proto - Attached On 2018-04-11 02:56:24 UTC - Size: 35.36 KB - 346 views
[2018-04-11 07:29:05]
User942837 - Posts: 108
Thank you for your reply. Yes I suspected that this wasn't the issue however at least now I know I have the correct proto3 file.

This line indicates that Sierra Chart received zero bytes from your client:
DTC client #6. 127.0.0.1 | No activity on network socket. Closing network socket. Bytes in receive buffer: 0 | 2018-04-10 09:23:47

So it actually did not send any data to Sierra Chart.


I've been trying many ways to connect to Sierra using the Google Protocol buffers but I am not yet to a stage where I am connecting.

I am definitely sending data to sierra but receiving no sort of error which tells me that either it is not being sent in the right format or some other reason. I am using same code that I am using to send a JSON message and have also tried using the WriteTo method but to no avail.

I know that you do not usually help in client code which is not the reason for sending this message but perhaps from your experience you could tell me what's the best way to write the bytes to Sierra DTC. These are the 3 versions I have tried. I initially also had a similar issue when communicating via JSON but this was solved by sending a null terminator but in this case I have no idea what to try next.
I would appreciate any help to identify what the problem might be as sierra is not reporting anything so I have no idea what I am doing wrong. Thanks a lot.

LogonRequest message = new LogonRequest();
message.HeartbeatIntervalInSeconds = 5;
message.ClientName = "Sample";
message.TradeMode = TradeModeEnum.TradeModeDemo;
message.HeartbeatIntervalInSeconds = 5;

    //Version 1) using WriteTo directly on the message and also tried WriteDelimitedTo which writes length and then data to the stream

TcpClient client = new TcpClient(ipServer, port);
var stream = client.GetStream();

// Send the message to the connected TcpServer.
var calculateSize = message.CalculateSize();

message.WriteTo(stream); // or using WriteDelimtedTo(stream)


    Version 2) Using CodedOutputStream

TcpClient client = new TcpClient(ipServer, port);
var stream = client.GetStream();

//Create Coded output stream to send data over the tcp client
CodedOutputStream cod = new CodedOutputStream(stream);

// Send the message to the connected TcpServer.
var calculateSize = message.CalculateSize();

message.WriteTo(stream);

    Version 3) Getting byte array for Google Proto to byte array and sending it.

byte[] bytes = message.ToByteArray();

// Send the data through the socket.
int bytesSent = dtcSocket.Send(bytes);
Date Time Of Last Edit: 2018-04-11 07:44:05
[2018-04-11 17:57:51]
Sierra Chart Engineering - Posts: 104368
I am definitely sending data to sierra
The Sierra Chart Message Log is indicating no data was received and that is quite accurate. However, disable the option to use TLS, if enabled, to eliminate that as a potential problem.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
Date Time Of Last Edit: 2018-04-11 18:13:23
[2018-04-11 18:05:34]
User942837 - Posts: 108
I already have TLS disabled.

I am definitely sending data to sierra.

Yes I am sending data. Sierra is not recognising it in the correct format and I do not know why.

Like I said I did manage to send JSON requests without issues but not Google Protocol messages. Can you confirm that what I told you I am doing is correct. Are you using CodedOutputStream to write to sockets?
Date Time Of Last Edit: 2018-04-11 18:06:59
[2018-04-12 19:44:20]
Sierra Chart Engineering - Posts: 104368
Are you using CodedOutputStream to write to sockets?
We do not know what this is.

Make sure you are sending the header before each Google protocol buffer message:
https://www.dtcprotocol.org/#GoogleProtocolBuffers
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2018-04-13 07:04:04]
User942837 - Posts: 108
Thank you for your reply.

In that link you have sent you are saying that

All DTC messages are then serialized into encoded blocks of data via the SerializeTo() methods in the generated API. These encoded messages are then sent over the network. Because the protocol buffer wire format is not self-delimiting, a small header is used to delimit and describe the encoded messages. The header is a 4-byte header containing a 2-byte unsigned integer size and a 2-byte unsigned integer message type. Each field is sent in little endian format.

There is an issue in the above because in C# there is no SerializeTo() methods that I could reference anywhere. The only method I found to write to a stream is to use the WriteTo() on the message (as per previous code samples). The header struct you are referring to is also not defined anywhere in the generated compiler code.

Would it be too much to ask if you could provide an example please in c# of just the login. I've literally searched everywhere I could.

Thank you
Date Time Of Last Edit: 2018-04-13 07:05:01

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account