Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Some tips here ...  RSS feed

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.
I'm trying to develope the following small app :
I have a server (using ServerSocket) that connects to a database and gets some strings.
my client will connect to this server and display the result (the server may writes 5 strings, 10 to the client ...).
my question is how to write the strings to the client ??
I'm not meaning how to get the streams or something, but I mean which streams to use ?
should I write a string then send "\n" ?
well, I just need some tips.
thanks.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're on your own to invent a protocol here. You suggested newlines. It would be simple to say the server returns comma separated values or delimited values with a newline at the end of each record and maybe two newlines together to mark the end of stream. Think about how you'd handle a memo or text field from the database that happens to have newlines or quotes in it.

If you'd like to send meta-data like column names and data types you could make up a header format and send those in front of the real data. HTTP puts two newlines between the headers and the data.

Give it some thought and make up a sample reply. I'm stopping short of doing that for you just on the chance this is school work. For school we like to see your ideas first.
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks...
This is my first try .
The server sends each string followed by \n char.
The client has the following :

Well, no problems here, it works
any other solutions or strategies (just to learn) ..
thanks.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the other stream classes. You could wrap the InputStream with an InputStreamReader and use its readLine() method. This returns the whole String for each line with the newline already removed.

DataInput/OutputStream will read and write all the primitive Java values along with a complete String (even if it has newlines embedded in it).
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys.
I'm thinking to create a small tool to intercept the traffic between the server and the client to monitor the data (like tcpmon of AXIS).
There are many tools available in the web (I think , packet sniffers), but I want to create my own tool to lean.
Any tips or hints how create such a tool ?
thanks all.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!