answersLogoWhite

0

server side networking application ServerSocket class is used, in this class method named as serversocket_object.accept() is used by server to listen to clients at specific port addresses, for local computer it is either "localhost" or "127.0.0.1" and might be u'r subnet address in case of some LAN.

User Avatar

Wiki User

17y ago

What else can I help you with?

Related Questions

How java supports networking?

Java supports both TCP and UDP connections. ServerSocket and Socket classes exist for TCP. DatagramSocket exists for UDP.


What is source server socket?

The ServerSocket bind to a local address and listens for new connections When a new connection arrives and the socket is managed by an IOManager a new Socket is created from the socket prototype provided on construction. You can also call accept() directly. The socket will then block until a new connection appears.


Source code for client server connection program by socket programming in Java?

Apologies in advance for the lengthy example. Below is an example of a client-server pair sending each other a message. This shows Java's TCP implementation of Server/ServerSocket classes because they're very simple and easy to use. A few things to be aware of when testing these classes out: # You can start one of these classes with TCPServer.start() or TCPClient.start(). # Always start the TCPServer class before the TCPClient class. If you don't, it's possible that the TCPClient will throw an exception and exit quietly, while the TCPServer class waits forever for a client to connect. # The current setup will connect on 127.0.0.1, which is your own computer. This will work even if you have no network/internet connection. If you wish to connect to a remote computer, change the TCPClient.HOST value to the IP address (or hostname) of the computer that will be running the server. // Code to run both parts of the program from the same computer. // (This will make for some jumbled output) class Main { public static void main(String[] args) { new TCPServer().start(); new TCPClient().start(); } } class TCPClient extends Thread { // Connection properties private static final String HOST = "127.0.0.1"; private static final int PORT = 56565; public void run() { // Socket class used for TCP connections Socket sock = null; // I/O components BufferedReader input = null; BufferedWriter output = null; try { // Connect our socket to the server. sock = new Socket(HOST, PORT); // Use a BufferedReader to read data from the server. input = new BufferedReader(new InputStreamReader(sock.getInputStream())); // Use a BufferedWriter to send data to the server. output = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream())); // Send some data to the server. String toServer = "Are you there, Server?"; System.out.println("ToServer: " + toServer); output.write(toServer); output.newLine(); output.flush(); // Wait for a response from the server and display it. String fromServer = input.readLine(); System.out.println("FromServer: " + fromServer); } catch (final IOException ex) { } finally { // Do our best to ensure a clean close procedure. // Closing the socket will also close input and output. try { if (sock != null) { sock.close(); } } catch (final IOException ex) { } } } } class TCPServer extends Thread { // Connection properties private static final int PORT = 56565; public void run() { // ServerSocket class used to accept TCP connections ServerSocket server = null; Socket sock = null; // I/O components BufferedReader input = null; BufferedWriter output = null; try { // Create our server on the given port. server = new ServerSocket(PORT); // Wait for a client to connect to us. sock = server.accept(); // Use a BufferedReader to read data from the client. input = new BufferedReader(new InputStreamReader(sock.getInputStream())); // Use a BufferedWriter to send data to the client. output = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream())); // Wait for the client to talk to us. String fromClient = input.readLine(); System.out.println("FromClient: " + fromClient); // Send them a response. String toClient = "Yes, I'm here, Client."; System.out.println("ToClient: " + toClient); output.write(toClient); output.newLine(); output.flush(); } catch (final IOException ex) { } finally { // Do our best to ensure a clean close procedure. // Closing the socket will also close input and output. try { if (sock != null) { sock.close(); } } catch (final IOException ex) { } // Close the server socket, as well. try { if (server != null) { server.close(); } } catch (final IOException ex) { } } } }


What are the classes of Mercedes-Benz?

a-class, b-class, c-class, cl-class, cls-class, cls-class(shooting brake), e-class, g-class, gl-class, glk-class, m-class, r-class, s-class, sl-class, slk-class


Is it 'the class have' or 'the class has'?

the class has ..


Is every class in java is subclass of itself?

A class can be a subclass of another class, not of itself.A class can be a subclass of another class, not of itself.A class can be a subclass of another class, not of itself.A class can be a subclass of another class, not of itself.


What is the possessive from of class?

The possessive form of "class" is "class's" or "class'".


When the class b is inherited from class a class a is called what?

Class B is said to be a "subclass" of class A.


What are some social classes?

low class, middle class, upper class/high class


What is nested class?

A class declared as a member of another class is called as a nested class or a class with in class. the general syntax of the nested class is: class outer_class_name{ private: //data protected: //data public: //methods class inner_class_name{ private: //data of inner class public: //methods of inner class };//end of inner class };//end of outer class


What class of ip address is 126.110.16.7?

It belongs to the class A.


How can you get the frequency of the preceding class interval when the modal class is the first class interval?

You cannot have a preceding class to the first class. There is no zeroth class.