Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Showing posts with label simple program for socket communication. Show all posts
Showing posts with label simple program for socket communication. Show all posts

Monday, 18 June 2012

Simple Socket Programming.

[ SENDER SIDE ]


import java.io.*;
import java.net.*;
public class sender
{
public static void main(String args[]) throws Exception
{
String msg="HELLO WORLD";
Socket soc=new Socket("localhost",3030);
DataOutputStream dos=new DataOutputStream(soc.getOutputStream());
dos.writeUTF(msg);
}
}


[ RECEIVER SIDE ]


import java.io.*;
import java.net.*;
public class receiver
{
public static void main(String args[]) throws Exception
{
String msg;
ServerSocket ss=new ServerSocket(3030);
Socket soc=ss.accept();
DataInputStream dis=new DataInputStream(soc.getInputStream());
msg=dis.readUTF();
System.out.println("Data received is : "+msg);
}
}