Hayes121
Hayes121

Reputation: 283

Creating Java TCP Protocol

So I am trying a little bit of network and socket programming, I have created simple client and server java application that will connect and allow users to enter messages and talk to each other.

Next I am trying to create a protocol for a game I am looking to make, the game involves 12 lights that are either on or off, the server will use a protocol to send the client values and depending on these values a certain light will turn on.

Example - 000000000100 will turn on light three

The protocol will work the same way from the client in that a button will be pressed and the string will be sent back to the server, the two strings will be checked if they match and if so the user will get a point.

The trouble I am having is where to begin? I have no major knowledge on creating protocols and looking to be pointed in the right direction.

If I send the binary string between client and server will that be considered a protocol or is there more to it?

Upvotes: 0

Views: 1507

Answers (2)

hcarrasko
hcarrasko

Reputation: 2352

If you will to create the protocol, this will be too easy, because the rules of the protocol will be established for you, and it depend of the nature of the system.

For example: If the system that you are creating the protocol is a simple chat, in the protocol you need put all data to allows the efective comunication between the server and the client. Example

>AAAA;MSG=BLABLA;TIME=12121212<

Suppose, it is the basic structure of you protocol, where ">" "<" are delimeters of you protocol (very useful), "AAAA" the type of message in case that you had more than one message. "MSG" the message, and "TIME" the time of transmission.

Like you see, you define that you want.

Upvotes: 1

Hypino
Hypino

Reputation: 1248

Really, a protocol is whatever you want it to be.

If you send 000000000100 to a server, and that server understands and responds appropriately, then you have a solid application-level protocol. In the context of your game this may be all your protocol even needs to be, or maybe you need to handle error cases (maybe 000000000100 is an invalid value), this is up to you.

However, you don't need to worry about things such as "did the server even get my message?" because TCP handles that. You probably don't want to get to the depth and complication that is TCP for something like this.

Upvotes: 1

Related Questions