Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

socket in java

public class GreetServer {
    private ServerSocket serverSocket;
    private Socket clientSocket;
    private PrintWriter out;
    private BufferedReader in;

    public void start(int port) {
        serverSocket = new ServerSocket(port);
        clientSocket = serverSocket.accept();
        out = new PrintWriter(clientSocket.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
        String greeting = in.readLine();
            if ("hello server".equals(greeting)) {
                out.println("hello client");
            }
            else {
                out.println("unrecognised greeting");
            }
    }

    public void stop() {
        in.close();
        out.close();
        clientSocket.close();
        serverSocket.close();
    }
    public static void main(String[] args) {
        GreetServer server=new GreetServer();
        server.start(6666);
    }
}
Comment

socket in java


writer.write("Hello user 1
");
writer.flush();

Comment

PREVIOUS NEXT
Code Example
Java :: binary to octal conversion java program 
Java :: how to stop activity from another activity 
Java :: in java how to compare two strings 
Java :: android studio get id name from view 
Java :: sublist java 
Java :: java arraylist remove 
Java :: java convert am pm to 24 hour 
Java :: initialize an array in java 
Java :: java sort arraylist of arraylist 
Java :: BottomNavigationView only icon 
Java :: Calling User-Defined Method in Java 
Java :: java program to sort an array 
Java :: where is java in ubuntu 
Java :: first line of java code 
Java :: get index of element in array java 
Java :: get date from calendar java 
Java :: minimum and maximum in array in java 
Java :: debug in java 
Java :: type of exception in java 
Java :: activityViewModels 
Java :: prime numbers program in java 
Java :: java read from file word by word 
Java :: remove whitespaces 
Java :: pass a function as parameter 
Java :: Number to decimal places in java 
Java :: android studio clock bar change color programmatically 
Java :: horizontal rule in android studio 
Java :: Calendar ranges java 
Java :: add infinite numbers to variable java 
Java :: java unique queue 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =