Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to write server?

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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.

  5. #5
    Junior Member
    Join Date
    Oct 2010
    Location
    USA
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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)
    ... Ellipsis ...
    Java | C/C++ | x86 Assembly | Python
    HTML | PHP | CSS | Flash Actionscript

Similar Threads

  1. how can i write this program
    By lavudyagopi27 in forum Java Theory & Questions
    Replies: 2
    Last Post: September 17th, 2010, 08:11 AM
  2. [SOLVED] How to write to an application
    By straw in forum Java Theory & Questions
    Replies: 4
    Last Post: June 19th, 2010, 10:17 AM
  3. write object to sql db
    By wolfgar in forum JDBC & Databases
    Replies: 3
    Last Post: May 18th, 2010, 10:03 AM
  4. How can i write this in code?
    By Mr. steve in forum Java Theory & Questions
    Replies: 2
    Last Post: November 30th, 2009, 10:07 PM
  5. How to write above a JPanel
    By bruno88 in forum AWT / Java Swing
    Replies: 4
    Last Post: June 23rd, 2009, 06:16 PM