1

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?

Dr.Haimovitz
  • 1,568
  • 12
  • 16
  • 1
    Nothing in the real world follows the OSI model, which, after all, is just a model. Your OS lumps layers 5, 6, and 7 into a single layer. – Ron Maupin Apr 17 '18 at 20:51
  • 'Breaking the model' is meaningless, especially as the OSI model was already broken ;-) – user207421 Apr 17 '18 at 23:42

1 Answers1

0

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.

Zac67
  • 2,761
  • 1
  • 10
  • 21
  • And if i would like to follow a protocol from the known protocols list at the application layer for the above use case which should i choose? – Dr.Haimovitz Apr 18 '18 at 11:55
  • You could select plain HTTP, WebDAV, XMPP, SOAP, or even FTP for instance. Anything that suits your need. – Zac67 Apr 18 '18 at 17:21
  • If i need just to send a few numbers to the server can i do it with http?? if not is there any other protocol i can use? – Dr.Haimovitz Apr 18 '18 at 22:40
  • 1
    Yes, see the list directly above. With HTTP, you could even transmit the actual data with a header entry (*X-age-value* or similar). – Zac67 Apr 19 '18 at 11:12