Simple android app that can connect to a specified address and stream data to it
Application uses ultra-modern communication protocol SDTUDTP3K (SDevTeam Ultra Data Transfer Protocol 3000). Here is its specification:
Server and client exchange with raw binary data (not strings!).
Commands may be of 2 types: control command and data command.
Control command is one single byte of data with following values (INPORTANT! Following constants are of type signed byte, sbyte
, char
in C++ or byte
in Java):
(client can send following commands):
0x1E
: "Hello server" message;0x31
: client is to change data command length (IMPORTANT! This command is followed with 4 bytes of length!);0x3F
: "Fone reset" command;0x45
: "Goodbye server" message;
(server can send following commands):
0x1A
: "Hello client" message;0x2D
: "Data received" server response;0x3E
: "Command executed" message;0x4C
: "Goodbye client" message;
(both server and client can send following commands):
0x66
: some error occured;
Data command is a bulk array of image data bytes, following the single byte with value 0x00
(to differ data command from control command).
First 2 bytes of this array represent image width (as a Java short
variable), and second ones represent image height.
This type of command can be sent only from client side.
See more in part Data Format
- Handshaking:
- Client (who starts the connection) sends "Hello server" message (
0x1E
). - Server sends "Hello client" message (
0x1A
). - Client sends
4
bytes that represent data command data length (without considering0x00
byte!).
NOTICE: there is a SDTUDTP3Km version of protocol, which does not includes data sending into handshake, but the first command after handshake is always length change command (0x31
), that is followed with 4 bytes of value of new data length.
-
After handshaking, data exchange starts:
-
Client sends data command.
-
Server sends "Data received" (
0x2D
) message. -
Can be repeated till the end of days.
-
If client answers with not a data command (first byte is not zero), it is a control command:
-
Client sends a command (see list above).
-
Server executes the command and sends "Command executed" message (
0x3E
) if succeeded. -
Server sends error message (
0x66
) if some error has occured while executing the command. Communication SHOULD NOT stop in this case. -
Closing the connection:
-
Client is always the initiator of closing the connection.
-
Client sends "Goodbye server" message (
0x45
). -
Server sends "Goodbye client" message (
0x4C
). -
Server closes the connection (socket).
-
Error handling:
-
If server has some internal error (important: not during execution of client command (3.2)), it sends error message
0x66
. -
If client has some internal error, it sends error message
0x66
. -
Crashed device doesn't have to close socket or send any other data. The other device should properly handle this situation.
-
If client crashes, server returns to "wait mode", awaiting a client to connect.
-
If server crashes, client returns to "connect" screen and should be ready for further attempts to connect to server.
Image is sent as raw byte sequence in format YUV NV_21
. For an appropriate conversion from it to RGB
, see this class (the last method in the file).
Raw image data follows 4 bytes representing image width
and height
, 2 bytes per value. They are stored as signed short integers (short
in Java).