Search code examples
network-programmingtcposi

Understanding the application layer in the osi model


I'm aware there are a lot of protocols at the application layer,

The question is more about when it is ok to not follow any of them,

Lets say i have a client and a server and the client app should send some data to that server, for instance, some statistics about a person using the app,

Now, for a good programming practice, is it ok to just open a tcp socket and send the data as is without the overhead of following a protocol or am i breaking the osi model and should i follow one of the protocols at the application layer? Am i reinventing the wheel here or is it a practical solution?


Solution

  • There's always an application layer protocol. If your concept is to transmit some statistics to a server ''on a certain TCP or UDP port as a plain, decimal number'' then that is your (implicit) application protocol. The protocol enables the server to receive data and assigns a meaning to the number.

    The OSI model is a model, not a law. In your application layer protocol you can do whatever you want.

    However, it may be useful to anticipate future expansion of the service, so that you could e.g. transmit value_a:data\0value_b:data in one stream/datagram without having to keep client and server versions in perfect sync (with the server not expecting all values and just ignoring unknown values). Of course, you can also use a different server port each time instead - your choice.