-
How to write server?
Hello! I am starting to write a simple server. The purpose of the server is to accept text file, parse the file and return the edited version to the client.
The examples of the server/client I have seen to far only have cases where client sends one line, then server sends one line.
But how do you send multiple lines? Do you have to accumulate the lines into ArrayList or something like that?
How do you detect end of document? Do you have to send special sequence of lines like blank line followed by a line with a single dot? (This is how the NNTP servers do it, I remember from many years ago I wrote client to NNTP server)
Can someone point to some examples of servers that accept multi line documents and send multi-line responses?
Thanks.
-
Re: How to write server?
By server I presume you mean an http type server? Data can be sent via get or post in a form text area, or uploaded from a file. The server can then process the data on server side (servlet, jsp, etc...). The server page can then output the response as html text in a page, or as a downloadable file by setting the header type. If you are truly writing your own server, then more information on the client/server communication would help
-
Re: How to write server?
I am talking about writing my own server using sockets. I don't need the overhead of the http server.
-
Re: How to write server?
Again, information about the client is helpful...custom, browser, etc..? Presuming its a custom client, just open up the socket connection and read/write the streams.
-
Re: How to write server?
You're going to have to come up with some form of protocol for your socket connections. How do the two communicate with each other? I find myself in your situation often when I write client/server applications. I've finally developed a consistent protocol I use but I suggest getting it down on paper. Take a pen and paper and draw out how the two establish a connection and how they continue it.
Perhaps within the first request sent to the server you could tell it how many lines to expect then the server waits until it receives that many lines, then processes them, and then in the first response back to the client it does the same thing (tells the client how many lines to expect and then sends that many back to the client).
Designing these sorts of protocols aren't terribly difficult you just need to really think it through and, like I said, I find it easier to do this with pen and paper and diagrams to work out how it all will operate and then try to code it.
Good luck!
(Also, as was said, if you need more help post more information about how the client/server communicate)