Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Help! ClientServer coordinate translation system

Posted on 2003-03-31
7
Medium Priority
?
161 Views
Last Modified: 2010-03-31
im currently doing a ClientServer coordinate translation system. this system has to be multi threaded too. i had briefly made a standalone program. how do i implement client server & multi threading to my this standalone system?? as in how do i send the program across when a user had successfully logged onto the server?
Thanks
0
Comment
Question by:cedric_rhea
5 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 8244281
 The best place to start is here: http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html

  which has a client-server tutorial and explains how you can turn it into a multiclient application. You can alos take a look here:

http://www.javaworld.com/javaworld/jw-12-1996/jw-12-sockets.html
http://developer.java.sun.com/developer/onlineTraining/Programming/BasicJava2/socket.html
0
 
LVL 1

Expert Comment

by:pronane
ID: 8245401
Are you trying to send a program across, then you will need to use RMI - Remote method calls - javas rpc standard, or you could use JINI, all these are on the java website, a simple client server program that is threaded wont be able to call a method from the server.
0
 
LVL 30

Accepted Solution

by:
Mayank S earned 280 total points
ID: 8260168
Ok, here is a small skeleton of a simple multithreaded (server-side of a) client-server program (assuming that strings are exchanged between the client and the server):

class MainServer
{
 public static void main ( String args[] )
   throws Exception
 {
   ServerSocket ss = new ServerSocket ( <port-no> ) ;
   Socket s = ss.accept () ; // accept a new connection from a client
   new ServerThread ( s ) ; // start a new thread to serve this client dedicatedly

 } // end of main ()

} // class definition over

class ServerThread extends Thread
{
 Socket s ;
 BufferedReader br ;
 PrintWriter pw ;

 ServerThread ( Socket s )
 {
   try
   {
     this.s = s ;  
     br = new BufferedReader ( new InputStreamReader ( s.getInputStream () ) ) ;
     pw = new PrintWriter ( s.getOutputStream (), true ) ;

   } // end of try block

   catch ( Exception e )
   {
     System.out.println ( "\n Exception: " + e ) ;
     return ;

   } // end of catch block

   start () ; // new thread

 } // end of constructor ()

 public void run ()
 {
   try
   {
     while ( true )
     {
       // put entire functionality of the server here
       // use pw.println () to send data,
       // br.readLine () to read

       if ( <some-exiting-condition> ) // like, the client wishes to log out
         return ; // kill this thread

     } // end while
     
   } // end of try block

   catch ( Exception e ) // client gets disconnected by, say, a power-failure
   {
     System.out.println ( "\n Exception: " + e ) ;
     return ; // kill this thread

   } // end of catch block

 } // end of run ()

} // class definition over


Hope that helps as a building block!

Mayank.
0
 

Expert Comment

by:CleanupPing
ID: 9058359
cedric_rhea:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 9371555
Recommendation: Accept mayankeagle's comment as answer.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question