This blog is Made specially for Bsc_IT students,Here you get all the notes question papers with easy downloadable link with Google docs and solution to your every query s.
Showing posts with label Internet Technology. Show all posts
Showing posts with label Internet Technology. Show all posts
Thursday, 7 April 2011
Sunday, 3 April 2011
SOCKET PROGRAMMING
Socket programming and Rmi programming is important part of Internet Technology, Its weight-age is about 16-24 marks with each question for 8 marks is fixed. One can easily score good marks in I.T by practicing Socket and Rmi Programs.
Note: All Rmi and Socket Programs are almost same only the logical part changes i.e 95% of all your programs is same coding that is a real advantage for students.
Here are the Few samples:
TCP Socket:
import java.net.*;
import java.io.*;
class EchoClient
{
public static void main(String[] args) throws Exception
{
Socket sock = new Socket("127.0.0.1",1099);
BufferedReader kbin = new BufferedReader(new InputStreamReader(System.in));
BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
PrintStream out = new PrintStream(sock.getOutputStream());
while(true)
{
System.out.print("Enter a msg : ");
String msg = kbin.readLine();
out.println(msg);
if(msg.equals("bye"))
break;
System.out.println(in.readLine());
}
sock.close();
}
}
import java.net.*;
import java.io.*;
class EchoServer
{
public static void main(String[] args) throws Exception
{
ServerSocket ss = new ServerSocket(1099);
while(true)
{
Socket sock = ss.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
PrintStream out = new PrintStream(sock.getOutputStream());
while(true)
{
String msg = in.readLine();
if(msg.equals("bye"))
break;
out.println("Server says : "+msg);
}
sock.close();
}
}
}
import java.rmi.*;
class strclient
{
public static void main(String ar[]) throws Exception
{
strrev sr = (strrev)Naming.lookup("rmi://localhost/strreverse");
System.out.println("Reverse of hello is : "+sr.rev("hello"));
}
}
Note: All Rmi and Socket Programs are almost same only the logical part changes i.e 95% of all your programs is same coding that is a real advantage for students.
Here are the Few samples:
TCP Socket:
Client side
import java.net.*;
import java.io.*;
class EchoClient
{
public static void main(String[] args) throws Exception
{
Socket sock = new Socket("127.0.0.1",1099);
BufferedReader kbin = new BufferedReader(new InputStreamReader(System.in));
BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
PrintStream out = new PrintStream(sock.getOutputStream());
while(true)
{
System.out.print("Enter a msg : ");
String msg = kbin.readLine();
out.println(msg);
if(msg.equals("bye"))
break;
System.out.println(in.readLine());
}
sock.close();
}
}
Server Side:
import java.net.*;
import java.io.*;
class EchoServer
{
public static void main(String[] args) throws Exception
{
ServerSocket ss = new ServerSocket(1099);
while(true)
{
Socket sock = ss.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
PrintStream out = new PrintStream(sock.getOutputStream());
while(true)
{
String msg = in.readLine();
if(msg.equals("bye"))
break;
out.println("Server says : "+msg);
}
sock.close();
}
}
}
Rmi(Remote Method Invocation):Program for String Reverse
Create Interface
import java.rmi.*;
public interface strrev extends Remote
{
String rev(String ip) throws RemoteException;
}
Implementation
import java.rmi.*;
import java.rmi.server.*;
public class strrevimpl extends UnicastRemoteObject implements strrev
{
public strrevimpl() throws RemoteException
{
super();
}
public String rev(String ip) throws RemoteException
{
StringBuilder sb = new StringBuilder(ip);
String s = (sb.reverse()).toString();
return(s);
}
}
Client Side
import java.rmi.*;
class strclient
{
public static void main(String ar[]) throws Exception
{
strrev sr = (strrev)Naming.lookup("rmi://localhost/strreverse");
System.out.println("Reverse of hello is : "+sr.rev("hello"));
}
}
Server Side
import java.rmi.*;
class strserver
{
public static void main(String ar[]) throws Exception
{
strrevimpl s = new strrevimpl();
Naming.rebind("rmi://localhost/strreverse",s);
System.out.println("Object successfully created");
}
}
This were the sample programs one can contact me if any doubt or for rest of programs if required.
Labels:
Internet Technology
Subscribe to:
Posts (Atom)