Java basics
getInetAddress()
Returns the address to which the socket is connected.
Syntax:getInetAddress()
Example:import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
public class SocketDemo {
public static void main(String[] args) {
try {
ServerSocket server = new ServerSocket(6123);
while (true) {
System.out.println("Listening");
Socket sock = server.accept();
InetAddress addr = sock.getInetAddress();
System.out.println("Connection made to "
+ addr.getHostName()
+ " (" + addr.getHostAddress() + ")");
pause(5000);
sock.close();
}
}
catch (IOException e) {
System.out.println("Exception detected: " + e);
}
}
private static void pause(int ms) {
try {
Thread.sleep(ms);
}
catch (InterruptedException e) {
}
}
}
Content
License.
All information of this service is derived from the free sources and is provided solely in the form of quotations.
This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 34 / 159176538. Delta: 0.00279 с