Wednesday, January 19, 2011

Telnet Server

 Telnet Server
//this code sends a string to a client whenever client connects it
// sends the response to client when command "1" is received
import java.lang.*;

class TelnetServer {
   public static void main(String args[]) {
      String data = "Hello Client!! ";
      try {
          // Create object of Server Socket
         ServerSocket srvr = new ServerSocket(8088);
          // Socket object that listens the port (8088) and accepts the incoming connection
         Socket skt = srvr.accept();
         System.out.println("Client Connected!");
         // gets output stream object 
         PrintWriter out = new PrintWriter(skt.getOutputStream(), true);
         //gets input stream object   
         DataInputStream din=new DataInputStream(skt.getInputStream());       
         // sends response to incoming request if command is '1'   

         System.out.println("String: '" + data);
         out.close();// clos out
         skt.close();// close skt
         srvr.close();// close srvr
         din.close(); // close din
      catch(Exception e) {

Telnet Client Source

1 comment: