/* this is simple client program in java connecting server 127.0.0.1(localhost) with port no 8000 */
//regular import
import java.net.*;
import java.io.*;
public class client
{
Socket cli;
DataInputStream din;
DataOutputStream dos;
public void start()
{
try
{
cli=new Socket("127.0.0.1",8000);
din=new DataInputStream(cli.getInputStream());
dos=new DataOutputStream(cli.getOutputStream());
dos.writeUTF("hello server...........");
String str=din.readUTF();
System.out.println(str);
cli.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String args[])
{
client c;
c=new client();
c.start();
}
}
Wednesday, March 12, 2008
Simple Client
Posted by Rohit Lagu 0 comments
Simple Server
/* This is simple server program in java running with port no 8000 */
import java.net.*;
import java.io.*;
public class server
{
ServerSocket ss;
Socket c;
DataInputStream din;
DataOutputStream dos;
public void start()
{
try{
ss=new ServerSocket(8000);
c=ss.accept();
din=new DataInputStream(c.getInputStream());
dos=new DataOutputStream(c.getOutputStream());
String str=din.readUTF();
System.out.println(str);
dos.writeUTF("hello client........");
c.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String args[])
{
server ser;
ser=new server();
ser.start();
}
}
Posted by Rohit Lagu 1 comments
Subscribe to:
Posts (Atom)
Sign by Rohit Lagu - SUPPORTED BY WE AND COMPUTER