Server And Client between Connection
Server :
import java.io.*;
import java.net.*;
class Server
{
public static void main(String[]args)
{
try
{
ServerSocket ss=new ServerSocket(6666);
Socket s=ss.accept();
System.out.println("socket connection etablished");
DataInputStream dis=new DataInputStream(s.getInputStream());
String str =(String)dis.readUTF();
System.out.println("message="+str);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Client:
import java.io.*;
import java.net.*;
class Client
{
public static void main(String[]args)
{
try
{
Socket s=new Socket("localhost",6666);
DataOutputStream dis=new DataOutputStream(s.getOutputStream());
dis.writeUTF("hello server");
dis.flush();
dis.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Server :
import java.io.*;
import java.net.*;
class Server
{
public static void main(String[]args)
{
try
{
ServerSocket ss=new ServerSocket(6666);
Socket s=ss.accept();
System.out.println("socket connection etablished");
DataInputStream dis=new DataInputStream(s.getInputStream());
String str =(String)dis.readUTF();
System.out.println("message="+str);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Client:
import java.io.*;
import java.net.*;
class Client
{
public static void main(String[]args)
{
try
{
Socket s=new Socket("localhost",6666);
DataOutputStream dis=new DataOutputStream(s.getOutputStream());
dis.writeUTF("hello server");
dis.flush();
dis.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
0 comments:
Post a Comment