Java custom Protocol client-server
<p>I'm trying to create a client-server application in Java.
This application will be transferring images from client to server.
The requirements is that application needs to be in network byte order. (Image below)</p>

<p>This will help me to learn how to deploy other protocols in the future, so looking for some tips in how to implement this. Currently I have my server-client working and transferring images, but not sure how to implement the protocol.</p>

<p>Thanks</p>

<p>This is my current server/client code:
<pre></p>

<p>public class NetworkServer {</p>

<code>public static void main(String[] args) {

    NetworkServer servidor = new NetworkServer();
    System.out.println("Server started()");
    BufferedInputStream bis;
    BufferedOutputStream bos;
    int num;
    File file = new File("/images");
    if (!(file.exists())){
      file.mkdir();
    }

    try {
      ServerSocket socket = new ServerSocket(15000);
      Socket incoming = socket.accept();

      try {
        try{
          if (!(file.exists())){
            file.mkdir();
          }
          InputStream inStream = incoming.getInputStream();
          OutputStream outStream = incoming.getOutputStream();

          BufferedReader inm = new BufferedReader(new InputStreamReader(inStream));
          PrintWriter out = new PrintWriter(outStream, true /* autoFlush */);
          String filelength = inm.readLine();
          String filename = inm.readLine();
          System.out.println("Server() Filename = " + filename);
          System.out.println("Server() File lenght: " + filelength + " bytes");
          System.out.println("Server() ACK: Filename received = " + filename);

          //RECIEVE and WRITE FILE
          byte[] receivedData = new byte[1000000];
          bis = new BufferedInputStream (incoming.getInputStream());
          bos = new BufferedOutputStream (new FileOutputStream("/images" + "/" + "image.jpg"));


          while ( (num = bis.read(receivedData)) &gt; 0){
            bos.write(receivedData,0,num);
          }
          bos.close();
          bis.close();

          File receivedFile = new File(filename);
          long receivedLen = receivedFile.length();
          System.out.println("Server() ACK: Length of received file = " + receivedLen);

        } finally {
          incoming.close();
       }
      } catch (IOException e){
        e.printStackTrace();
      }
    } catch (IOException e1){
      e1.printStackTrace();
    }
            }
    }
</code></pre>

<p></p>

<p><img src="http://i.stack.imgur.com/p7StR.jpg" alt="Protocol"></p>
