第二章 Socket用法详解

本文详细介绍了Socket的使用,包括构造方法、连接超时、服务器地址设定、客户端地址设定、异常处理,以及Socket信息获取、关闭、半关闭状态、设置Socket选项等。此外,还提及了TCP_NODEALY、SO_RESUSEADDR等关键选项,并简单提及了SMTP客户程序的Socket应用。
摘要由CSDN通过智能技术生成
构造Socket

  Socket构造方法如下:

 1 Socket() 
 2 //Creates an unconnected socket, with the system-default type of SocketImpl.
 3  
 4 Socket(InetAddress address, int port) 
 5 //Creates a stream socket and connects it to the specified port number at the  
 6 //specified IP address.
 7  
 8 Socket(InetAddress host, int port, boolean stream) 
 9 //Deprecated.  
10 //Use DatagramSocket instead for UDP transport.
11  
12 Socket(InetAddress address, int port, InetAddress localAddr, int localPort) 
13 //Creates a socket and connects it to the specified remote address on the 
14 //specified remote port.
15  
16 Socket(Proxy proxy) 
17 //Creates an unconnected socket, specifying the type of proxy, if any, that 
18 //should be used regardless of any other settings.
19  
20 Socket(SocketImpl impl) 
21 //Creates an unconnected Socket with a user-specified SocketImpl.
22  
23 Socket(String host, int port) 
24 //Creates a stream socket and connects it to the specified port number on the  
25 named host.
26  
27 Socket(String host, int port, boolean stream) 
28 //Deprecated.  
29 //Use DatagramSocket instead for UDP transport.
30  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值