package com.HM.Objecttcp;
import java.io.Serializable;
public class Student implements Serializable{
int id;
String name;
int age;
String department;
public Student(int id, String name,int age,String department){
this.id = id;
this.name = name;
this.age = age;
this.department = department;
}
}
package com.HM.Objecttcp;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class ObjectServer {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
ServerSocket ss = new ServerSocket(8001);
Socket s = ss.accept();
OutputStream ops = s.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(ops);
Student stu = new Student(19,"wanghh",22,"huaxue");
oos.writeObject(stu);
oos.close();
s.close();
ss.close();
}
}
package com.HM.Objecttcp;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.net.Socket;
import java.net.UnknownHostException;
public class ObjectClient {
/**
* @param args
* @throws Exception
* @throws UnknownHostException
*/
public static void main(String[] args) throws UnknownHostException,
Exception {
Socket s = new Socket("127.0.0.1", 8001);
InputStream ips = s.getInputStream();
ObjectInputStream ois = new ObjectInputStream(ips);
Student stu = (Student) ois.readObject();
System.out.println("id is " + stu.id);
System.out.println("name is " + stu.name);
System.out.println("age is " + stu.age);
System.out.println("department is " + stu.department);
ois.close();
s.close();
}
}
id is 19
name is wanghh
age is 22
department is huaxue
ftp协议支持tcp协议吗。。。?
tcp协议可以保证计算机之间正确的传送数据,但是不保证接收方是否能理解发送方数据的意义,
而ftp协议是建立在tcp协议之上的,为在Internet网络上传送文件而定义的一种协议。
所以tcp协议相当于电话系统,而ftp协议相当于打电话的人所约定的语言规则 。
有的应用程序协议时在两个程序之间传递邮件,例如:smtp和pop3
有的应用程序协议是在两个程序之间传送文件:例如:ftp
有的应用程序协议是在两个程序之间传送3w网页,例如:http协议
我的上次这个项目就是对方规定的一票协议:我把它组装成字节流发出去,那么这个协议就是我们自己规定的
怎么区分ASP,JSP与网络编程的概念:
ASP,JSP相当于制造电视节目,而网络编程相当于制造卫星系统用于发送和接收这些节目