Simple java class code that implements Serializable,ServerSocket, InputStream,ObjectInputStream, Socket
import java.net.*;
import java.io.*;
class ShopItem implements Serializable{
int shopid;
String name;
float cost;
public ShopItem(int id, String s, float c){
this.shopid=id;
this.name=s;
this.cost=c;
}
}
public class ObjectServer {
public static void main(String args[]){
int port=2002;
try{
ServerSocket ss=new ServerSocket(port);
Socket s=ss.accept();
InputStream is=s.getInputStream();
ObjectInputStream ois=new ObjectInputStream(is);
ShopItem to=(ShopItem)ois.readObject();
if(to!=null){
System.out.println("Object Details");
System.out.println(to.shopid);
System.out.println(to.name);
System.out.println(to.cost);
}
is.close();
s.close();
ss.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
import java.io.*;
class ShopItem implements Serializable{
int shopid;
String name;
float cost;
public ShopItem(int id, String s, float c){
this.shopid=id;
this.name=s;
this.cost=c;
}
}
public class ObjectServer {
public static void main(String args[]){
int port=2002;
try{
ServerSocket ss=new ServerSocket(port);
Socket s=ss.accept();
InputStream is=s.getInputStream();
ObjectInputStream ois=new ObjectInputStream(is);
ShopItem to=(ShopItem)ois.readObject();
if(to!=null){
System.out.println("Object Details");
System.out.println(to.shopid);
System.out.println(to.name);
System.out.println(to.cost);
}
is.close();
s.close();
ss.close();
}
catch(Exception e){
System.out.println(e);
}
}
}
Comments
Post a Comment