Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The protocol is of importance here. Either you can design a text protocol like the KnockKnockProtocol in the example. e.g:</p> <pre><code>client: LIST server: FILES foo.txt bar.txt client: DETAILS bar.txt server: DETAILS bar.txt 123421 0644 myuser mygroup client: GET bar.txt server: FILEDATA bar.txt &lt;base64-encoded content or such&gt; client: QUIT </code></pre> <p>But there are already many of those around, designing good protocols is hard and it is quite easy to write bugs in parsers etc. It's generally not worth it.</p> <p>But... You use java for both client and server and java can serialize objects so you can send whole objects through network streams. That way you don't have to bother with parsing issues.</p> <p>Just read the network socket through <a href="http://download.oracle.com/javase/6/docs/api/java/io/ObjectInputStream.html" rel="nofollow">ObjectInputStream</a> and write through <a href="http://download.oracle.com/javase/6/docs/api/java/io/ObjectOutputStream.html" rel="nofollow">ObjectOutputStream</a>. That way you can have classes that model the requests and responses of your protocol.</p> <pre><code>public interface Request implements Serializable { } public class ListFilesRequest implements Request { } public class FileDetailsRequest implements Request { public String fileName; } public class DownloadFileRequest implements Request { public String fileName; } public interface Response implements Serializable { } public class FileListResponse implements Response { public String[] fileNames; } public class FileDetailsResponse implements Response { public String fileName; public int fileSize; public int fileMode; } public class FileDataResponse implements Response { public String fileName; public byte[] fileData; } </code></pre> <p>Then server could do something like:</p> <pre><code>ObjectInputStream objInput = new ObjectInputStream(mySocket.getInputStream()); ObjectOutputStream objOutput = new ObjectOutputStream(mySocket.getOutputStream()); Object requestObject = objInput.readObject(); Response responseObject = null; if (requestObject instanceOf ListFilesRequest) { FileListResponse response = new FileListResponse(); response.fileNames = new String[] { "foo.txt", "bar.txt" }; responseObject = response; } else if (requestObject instanceOf FileDetailsRequest) { FileDetailsRequest request = (FileDetailsRequest)requestObject; String fileName = request.fileName; ... } objOutput.writeObject(responseObject); </code></pre> <p>...or something like this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload