July 30, 2008 at 4:45 PM
Hi friend,
import java.io.*;
import java.net.*;
public class KnockKnockClient {
public static void main(String[] args) throws IOException {
Socket soc = null;
PrintWriter out = null;
BufferedReader in = null;
try {
soc = new Socket("vinod", 135);
out = new PrintWriter(soc.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(soc.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Don't know about host: vinod.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to: vinod.");
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String fromServer;
String fromUser;
while ((fromServer = in.readLine()) != null) {
System.out.println("Server: " + fromServer);
if (fromServer.equals("Bye."))
break;
fromUser = stdIn.readLine();
if (fromUser != null) {
System.out.println("Client: " + fromUser);
out.println(fromUser);
}
}
out.close();
in.close();
stdIn.close();
soc.close();
}
}
----------------------------------------------------------------
Read for more information.
http://www.roseindia.net/java/network/interfaces-list.shtmlThanks.
Related Tutorials/Questions & Answers:
Advertisements
ModuleNotFoundError: No module named 'sockets'ModuleNotFoundError: No module named '
sockets' Hi,
My Python... '
sockets'
How to remove the ModuleNotFoundError: No module named '
sockets... to install padas library.
You can install
sockets python with following command
Server Sockets
Server
Sockets
In common language we can say that the
sockets are just like...
Sockets. The main
work of ServerSocket class is to wait for a request of connection
Server Sockets
Server
Sockets
In common language we can say that the
sockets are just like...
Sockets. The main
work of ServerSocket class is to wait for a request of connection