Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

NETWORK COMMUNICATION USING TCP/IP

PROGRAM
import java.io.*;
import java.net.*;
class tcpser
{
public static void main(String arg[])
{
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
ServerSocket ob=new ServerSocket(95);
Socket obj=ob.accept();
OutputStream op=obj.getOutputStream();
System.out.println("Enter a string (x to exit)");
String str;
do
{
str=br.readLine();

op.write(str.getBytes());
}while(!str.equals("x"));
op.close();
obj.close();
}
catch(Exception ex)
{
}
}
}


import java.io.*;
import java.net.*;
class tcpcl
{
public static void main(String arg[])
{
try
{
Socket ob=new Socket("localhost",95);
InputStream ip=ob.getInputStream();
String t;
do
{
byte b[]=new byte[ip.available()];
ip.read(b);
t=new String(b);
System.out.println(t);
}while(!t.equals("x"));
ip.close();
ob.close();
}
catch(Exception ex)
{
}
}
}

OUTPUT

Enter a string (x to exit)
Are U there?
Hai..Listen to me
x

Are U there?
Hai..Listen to me
x

NETWORK COMMUNICATION USING TCP/IP is a post from ShoutToWorld - Let's Learn Let's Shout - Helping bloggers and developers.



This post first appeared on ShoutToWorld, please read the originial post: here

Share the post

NETWORK COMMUNICATION USING TCP/IP

×

Subscribe to Shouttoworld

Get updates delivered right to your inbox!

Thank you for your subscription

×