Simón Farias
Simón Farias

Reputation: 772

How to replicate the Traccar Sever connection to a device (castel protocol by TCP) in a single Java class? (to connect, disconnect encode and decode)

  1. THE CASE:

I have a TCP client what send a data and I want to hear the data from my server. So, here, everything okay.

I decided make an socket server on port 9876 to listen this device (using Java 8). The data which I receive is weird, when I print it is like: "慳慳慳", but in theory, the data coming should be a hex. This is an example of the package what the device sends (login):

40407F000431303031313132353239393837000000000000001001C1F06952FDF069529C91110000000000698300000
C0000000000036401014C00030001190A0D04121A1480D60488C5721800000000AF4944445F3231364730325F53205
6312E322E31004944445F3231364730325F482056312E322E31000000DF640D0A

I want to replicate in a easy way (one class if its possible) the connection by castel to the device (port 5086 for Traccar server app) in almost 6 methods:

My goal is replicate this behavior with PHP. I tried with Websocket/HTTP protocols and the result is that I can't connect with it. I cant hear any package from the device.

So, other question could be: how I can code my own custom protocol (Castel) to connect server with these devices?

I reviewed the Traccar Server code, but its very extensive. I proved the device with it and it works, but I can't understand how (at the code level).

  1. Documentation

Communication flow

Protocol package format for download upload

Upvotes: 0

Views: 481

Answers (1)

Anton Tananaev
Anton Tananaev

Reputation: 2523

Traccar server includes a lot of different things, but you can just take the protocol parsing part if you want. Here's the decoder for the Castel protocol:

github.com/traccar/.../CastelProtocolDecoder.java

The decoder is based on Netty, so if you want to use it, you need to implement the rest of the server to listen to incoming connections. I would recommend checking Netty guide for more details on how to do it:

https://netty.io/wiki/user-guide-for-4.x.html

Upvotes: 1

Related Questions