简体   繁体   中英

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:

  • Connect
  • Disconnect
  • Encode
  • Decode
  • Send package
  • Receive package

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
  • Castel communication flow

通讯流程

  • Protocol package format for download upload

下载上传协议包格式

  • Login package example登录包

  • I did a simple socket with PHP and this is what I listenedPHP 套接字监听

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM