电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

试验七应用层网络编程

试验七应用层网络编程_第1页
1/8
试验七应用层网络编程_第2页
2/8
试验七应用层网络编程_第3页
3/8
浙江大学城市学院实验报告课程名称计算机网络应用实验项目名称实验七应用层网络编程(一)实验成绩指导老师(签名)日期 2014-06-03 一. 实验目的和要求1.通过实现使用 Java 应用层客户端和服务器来获得关于使用Java Socket 网络编程的经验( SMTP、POP3)。二. 实验内容、原理及实验结果与分析1. SMTP 编程(参考电子讲义“网络编程参考资料-应用层 .pdf ”及教材“第2 章Socket 编程”)阅 读“ 网络 编 程参考 资 料 - 应 用层 .pdf ”“ SMTP客 户机 实 现” 的 源 代 码(SMTPClientDemo.java ),并在机器上编译运行通过。 (注:可输入城院 SMTP 邮件服务器或其他邮件服务器作为SMTP 服务器)【程序源代码】SMTPClientDemo.java import java.io.*; import java.net.*; import java.util.*; // Chapter 8, Listing 1 public class SMTPClientDemo { protected int port = 25; protected String hostname = "localhost"; protected String from = ""; protected String to = ""; protected String subject = ""; protected String body = ""; protected Socket socket; protected BufferedReader br; protected PrintWriter pw; // Constructs a new instance of the SMTP Client public SMTPClientDemo() throws Exception { try { getInput(); sendEmail(); } catch (Exception e) { } } public static void main(String[] args) throws Exception { // Start the SMTP client, so it can send messages SMTPClientDemo client = new SMTPClientDemo(); } // Check the SMTP response code for an error message protected int readResponseCode() throws Exception { String line = br.readLine(); line = line.substring(0,line.indexOf(" ")); return Integer.parseInt(line); } // Write a protocol message both to the network socket and to the screen protected void writeMsg(String msg) throws Exception { pw.println(msg); pw.flush(); } // Close all readers, streams and sockets protected void closeConnection() throws Exception { pw.flush(); pw.close(); br.close(); socket.close(); } ...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

试验七应用层网络编程

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部