How develop server in java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Abhinay
    New Member
    • Jul 2006
    • 44

    How develop server in java

    Hi there,

    I am new in java, I was C++ developer.
    I have to develop echo server using java which would be run on windows , I am ready with server logic.

    I am stuck in basic code of java server as I don't understand how to write code for server start / stop as well run java server as daemon process ( like C++ ).

    Is there any thing in java simillar to windows services in C++ ??

    Please suggest me, your help will make me happy.

    Thank you
    Abhinay
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Start reading the API documentation for the ServerSocket class; such an object can accept incoming Sockets, read data from them and write it back again (the 'echo' functionality). Keep accepting sockets on the server socket until you stop the loop.

    Running the entire thing as a daemon is beyond the scope of Java; you have to start the JVM as a daemon; its a shell/command line job.

    kind regards,

    Jos

    Comment

    • Abhinay
      New Member
      • Jul 2006
      • 44

      #3
      Thank you very much for your suggestion, if posible can you please give me any idea for running server ( JVM ) as daemon in windows.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by Abhinay
        Thank you very much for your suggestion, if posible can you please give me any idea for running server ( JVM ) as daemon in windows.
        I don't know much about windows but type "help start"; the start command starts another command as a background process.

        kind regards,

        Jos

        Comment

        • chaarmann
          Recognized Expert Contributor
          • Nov 2007
          • 785

          #5
          You could run a normal java application that starts a daemon thread:

          Code:
           class MyThread extends Thread
          {
           MyThread()
           {
            this.setDaemon(true);
           }
           public void run()
           {
             ...
           }
          }

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by chaarmann
            You could run a normal java application that starts a daemon thread:
            But that still doesn't run the entire JVM as a daemon process ...

            kind regards,

            Jos

            Comment

            Working...