Q:

Java TCP server for communicating with an IoT device

I have developed an embedded system which sends data to a server as TCP requests.  I can't use more-frequent HTTP requests, because of its data overhead.  Less package length will result in less energy consumption and less communication expenses.  
The server has to listen to a special port, get the data from device and store in a table.  
As I explored, Java servlets + Apache Tomcat is a popular solution but in this case should not be used, because a Java servlet is more suitable for HTTP-based connections. 
Is there a better solution for this type of communication? 

A:

Please take a look at Sockets.  They are on the Application layer TCP/IP model and they provide reliable, bidirectional communication, with no data overhead.  However, you will need to design a tiny protocol for the communication to much your needs.  
Most probably this will suffice your needs, but if you decide to go with the HTTP solution, keep in mind Websockets which is an interesting solution, will diminish the overhead of the HTTP protocol (but they won't eliminate it, the overhead will remain at around 2-10 bytes.).  Unfortunately, Java SE doesn't built in provide support for Websockets so you will need to use an external library.  
PS: Both options support encryption over TLS but I didn't mention it, cause it adds a noticeable overhead (at least during the initialization of the connection)

