Wednesday, March 12, 2008

Simple Client

/* 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();
}
}

No comments:

Sign by Rohit Lagu - SUPPORTED BY WE AND COMPUTER