- 9
- 0
- 约 91页
- 2017-05-27 发布于河南
- 举报
第二章 Socket编程基础2013
网络编程技术
熊育婷
2013- 10
网络编程技术— 中国民航大学计算机学院
第2章 Socket用法详解
2.1 构造Socket (重点)
2.2 获取Socket 的信息 (重点)
2.3 关闭Socket
2.4 半关闭Socket
2.5 设置Socket 的选项
2.6 发送邮件的SMTP 客户程序 (难点)
2.7 Whois 的图形界面客户端程序 (难点)
2.1 构造Socket
A socket is a connection between two hosts.
It can perform seven basic operations:
Connect to a remote machine
Send data
Receive data
Close a connection
Bind to a port
Listen for incoming data
Accept connections from remote machines on the bound port
2.1 构造Socket
Socket 的构造方法有以下几种重载形式:
(1)Socket()
(2)Socket(InetAddress address, int port)throws IOException
(3)Socket(InetAddress address, int port, InetAddress
localAddr, int localPort)throws IOException
(4)Socket(String host, int port) throws,IOException
(5)Socket(String host, int port, InetAddress localAddr, int
localPort) throws IOException
2.1 构造Socket-InetAddress
.InetAddress class is Javas high-level
representation of an IP address, both IPv4 and
IPv6.
includes both a hostname and an IP address.
Methods initialized InetAddress objects :
public static InetAddress getByName(String hostName) throws
UnknownHostException
public static InetAddress[] getAllByName(String hostName)
throws UnknownHostException
public static InetAddress getLocalHost( ) throws
UnknownHostException
2.1 构造Socket-InetAddress
import .*;
public class OReillyByName {
public static void main (String[] args) {
try {
InetAddress address = InetAddress.getByName();
System.out.println(address);
}
catch (UnknownHostException ex) {
System.out.println(Could not find );
}
}
}
2.1 构造Socket-InetAddress
import .*;
public class AllAddressesOfMicrosoft {
public static void main (String[]
原创力文档

文档评论(0)