Results 1 to 4 of 4

Thread: Client server connection

  1. #1
    Join Date
    Aug 2009
    Posts
    57

    Client server connection

    To make a client server connection normally its the server waiting for a connection through
    Code:
    ServerSocket. Accept()
    but this method is blocking. Is there another way to create a method client/server connection that runs them at the same temps.ce means that this is not the server that is launched first.

  2. #2
    Join Date
    Nov 2008
    Posts
    1,054

    Re: Client server connection

    The server must always be started first, if you do not block the execution of your program I advise you to launch Thread, accept the waiting in a Thread, and the other side of management for each client is by a dedicated thread.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Client server connection

    A brief description is here. Here is short information:

    A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent.

    Normally, a server runs on a specific computer and has a socket that is bound to a specific port number. The server just waits, listening to the socket for a client to make a connection request.

  4. #4
    Join Date
    May 2008
    Posts
    685

    Re: Client server connection

    Here is an example:

    Code:
    public class Server implements Runnable{
    // Port on which your serverSocket will accept the connection
    private final int port=3333;
    // Server socket
    private ServerSocket serverSocket;
    // thread
    private Thread thServer;
    //variable to stop your thread (yad alternative)
    private boolean inPrivate=false;
     
    //Constructor
     public Server(){
      serverSocket=new ServerSocket(port);//instantiates the server socket
      thServer=new Thread(this,"My Server");//create the thread 
      thServer.start();//starts the thread's run
     }
    //run the thread 
     public void run(){
      inPrivate=true;
      while(inPrivate){
       serverSocket.accept();
      }
     }
    }
    But that does not do much except accept the connection. To you create a class to use your socket by replacing:
    Code:
     serverSocket. accept ( ) ;
    by
    Code:
    new Reception (server.accept());
    Code:
    public class Reception{
     BufferedInputStream bis;
     char read;
     public Reception(Socket mySocket){
      bis=new BufferedInputStream (mySocket.getInputStream());
      while((read=bis.read())!=-1){
       System.out.println(read);
      }
     }
    }
    Well it must miss the block try() catch() {}, must also pass reception in thread. Otherwise you will have concerns for a more connected to your server

Similar Threads

  1. Ubuntu server Hacked using openssh client connection
    By Tikoo in forum Networking & Security
    Replies: 4
    Last Post: 02-12-2011, 10:54 PM
  2. Replies: 7
    Last Post: 16-02-2011, 08:14 PM
  3. Replies: 5
    Last Post: 09-10-2010, 12:24 PM
  4. Replies: 2
    Last Post: 12-11-2008, 01:32 PM
  5. SSTP VPN Client connection
    By Juan in forum Windows Server Help
    Replies: 2
    Last Post: 19-06-2008, 08:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,046,508.81467 seconds with 17 queries