日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java setsolinger_java socket 的参数选项解读(转)

發(fā)布時間:2023/12/1 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java setsolinger_java socket 的参数选项解读(转) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

在MulticastSocket的源代碼里有設(shè)置多播的方法:

public void setInterface(InetAddress inf) throwsSocketException {

if(isClosed()) {

throw new SocketException("Socket is closed");

}

checkAddress(inf, "setInterface");

synchronized(infLock) {

getImpl().setOption(SocketOptions.IP_MULTICAST_IF, inf);

infAddress =inf;

}

}

7、public final static int IP_MULTICAST_IF2 = 0x1f;

這個字段的效果和上面的是一樣的,只是擴展支持IPV6

8、public final static int IP_MULTICAST_LOOP = 0x12;

用來設(shè)置本地回環(huán)接口的多播特性,在MulticastSocket源代碼中有相關(guān)方法:

/*** Disable/Enable local loopback of multicast datagrams

* The option is used by the platform's networking code as a hint

* for setting whether multicast data will be looped back to

* the local socket.

*

*

Because this option is a hint, applications that want to

* verify what loopback mode is set to should call

* {@link#getLoopbackMode()}

* @paramdisable true to disable the LoopbackMode

* @throwsSocketException if an error occurs while setting the value

* @since1.4

* @see#getLoopbackMode

*/

public void setLoopbackMode(boolean disable) throwsSocketException {

getImpl().setOption(SocketOptions.IP_MULTICAST_LOOP, Boolean.valueOf(disable));

}

9、public final static int IP_TOS = 0x3;

這個參數(shù)是用來控制IP頭中的TOS字段的,是用來控制和優(yōu)化IP包的路徑的,在Socket源代碼里有一個設(shè)置的方法:

/*** Sets traffic class or type-of-service octet in the IP

* header for packets sent from this Socket.

* As the underlying network implementation may ignore this

* value applications should consider it a hint.

*

*

The tc must be in the range 0 <= tc <=

* 255 or an IllegalArgumentException will be thrown.

*

Notes:

*

For Internet Protocol v4 the value consists of an octet

* with precedence and TOS fields as detailed in RFC 1349. The

* TOS field is bitset created by bitwise-or'ing values such

* the following :-

*

*

*

IPTOS_LOWCOST (0x02)

*

IPTOS_RELIABILITY (0x04)

*

IPTOS_THROUGHPUT (0x08)

*

IPTOS_LOWDELAY (0x10)

*

* The last low order bit is always ignored as this

* corresponds to the MBZ (must be zero) bit.

*

* Setting bits in the precedence field may result in a

* SocketException indicating that the operation is not

* permitted.

*

* As RFC 1122 section 4.2.4.2 indicates, a compliant TCP

* implementation should, but is not required to, let application

* change the TOS field during the lifetime of a connection.

* So whether the type-of-service field can be changed after the

* TCP connection has been established depends on the implementation

* in the underlying platform. Applications should not assume that

* they can change the TOS field after the connection.

*

* For Internet Protocol v6 tc is the value that

* would be placed into the sin6_flowinfo field of the IP header.

*

* @paramtc an int value for the bitset.

* @throwsSocketException if there is an error setting the

* traffic class or type-of-service

* @since1.4

* @see#getTrafficClass

*/

public void setTrafficClass(int tc) throwsSocketException {

if (tc < 0 || tc > 255)

throw new IllegalArgumentException("tc is not in range 0 -- 255");

if(isClosed())

throw new SocketException("Socket is closed");

getImpl().setOption(SocketOptions.IP_TOS, newInteger(tc));

}

從源代碼的注釋看,TOS設(shè)置了是否生效,和底層的操作系統(tǒng)的實現(xiàn)有關(guān)。應(yīng)用程序無法保證TOS的變更會對socket連接產(chǎn)生影響。個人認為,TOS在一般情況下用不到。

10、public final static int SO_LINGER = 0x0080;

先看Socket源代碼:

/*** Enable/disable SO_LINGER with the specified linger time in seconds.

* The maximum timeout value is platform specific.

*

* The setting only affects socket close.

*

* @paramon whether or not to linger on.

* @paramlinger how long to linger for, if on is true.

* @exceptionSocketException if there is an error

* in the underlying protocol, such as a TCP error.

* @exceptionIllegalArgumentException if the linger value is negative.

* @sinceJDK1.1

* @see#getSoLinger()

*/

public void setSoLinger(boolean on, int linger) throwsSocketException {

if(isClosed())

throw new SocketException("Socket is closed");

if (!on) {

getImpl().setOption(SocketOptions.SO_LINGER, newBoolean(on));

} else{

if (linger < 0) {

throw new IllegalArgumentException("invalid value for SO_LINGER");

}

if (linger > 65535)

linger = 65535;

getImpl().setOption(SocketOptions.SO_LINGER, newInteger(linger));

}

}

這個字段對Socket的close方法產(chǎn)生影響,當(dāng)這個字段設(shè)置為false時,close會立即執(zhí)行并返回,如果這時仍然有未被送出的數(shù)據(jù)包,那么這些數(shù)據(jù)包將被丟棄。如果設(shè)置為True時,有一個延遲時間可以設(shè)置。這個延遲時間就是close真正執(zhí)行所有等待的時間,最大為65535。

11、public final static int SO_TIMEOUT = 0x1006;

/*** Enable/disable SO_TIMEOUT with the specified timeout, in

* milliseconds. With this option set to a non-zero timeout,

* a read() call on the InputStream associated with this Socket

* will block for only this amount of time. If the timeout expires,

* a java.net.SocketTimeoutException is raised, though the

* Socket is still valid. The option must be enabled

* prior to entering the blocking operation to have effect. The

* timeout must be > 0.

* A timeout of zero is interpreted as an infinite timeout.

* @paramtimeout the specified timeout, in milliseconds.

* @exceptionSocketException if there is an error

* in the underlying protocol, such as a TCP error.

* @sinceJDK 1.1

* @see#getSoTimeout()

*/

public synchronized void setSoTimeout(int timeout) throwsSocketException {

if(isClosed())

throw new SocketException("Socket is closed");

if (timeout < 0)

throw new IllegalArgumentException("timeout can't be negative");

getImpl().setOption(SocketOptions.SO_TIMEOUT, newInteger(timeout));

}

這個參數(shù)用來控制客戶端讀取socket數(shù)據(jù)的超時時間,如果timeout設(shè)置為0,那么就一直阻塞,否則阻塞直到超時后直接拋超時異常。

12、public final static int SO_SNDBUF = 0x1001;

在默認情況下,輸出流的發(fā)送緩沖區(qū)是8096個字節(jié)(8K)。這個值是Java所建議的輸出緩沖區(qū)的大小。如果這個默認值不能滿足要求,可以用setSendBufferSize方法來重新設(shè)置緩沖區(qū)的大小。

13、public final static int SO_RCVBUF = 0x1002;

在默認情況下,輸入流的接收緩沖區(qū)是8096個字節(jié)(8K)。這個值是Java所建議的輸入緩沖區(qū)的大小。如果這個默認值不能滿足要求,可以用setReceiveBufferSize方法來重新設(shè)置緩沖區(qū)的大小。

14、public final static int SO_KEEPALIVE = 0x0008;

如果將這個參數(shù)這是為True,客戶端每隔一段時間(一般不少于2小時)就像服務(wù)器發(fā)送一個試探性的數(shù)據(jù)包,服務(wù)器一般會有三種回應(yīng):

1、服務(wù)器正常回一個ACK,這表明遠程服務(wù)器一切OK,那么客戶端不會關(guān)閉連接,而是再下一個2小時后再發(fā)個試探包。

2、服務(wù)器返回一個RST,這表明遠程服務(wù)器掛了,這時候客戶端會關(guān)閉連接。

3、如果服務(wù)器未響應(yīng)這個數(shù)據(jù)包,在大約11分鐘后,客戶端Socket再發(fā)送一個數(shù)據(jù)包,如果在12分鐘內(nèi),服務(wù)器還沒響應(yīng),那么客戶端Socket將關(guān)閉。

15、public final static int SO_OOBINLINE = 0x1003;

如果這個Socket選項打開,可以通過Socket類的sendUrgentData方法向服務(wù)器發(fā)送一個單字節(jié)的數(shù)據(jù)。這個單字節(jié)數(shù)據(jù)并不經(jīng)過輸出緩沖區(qū),而是立即發(fā)出。雖然在客戶端并不是使用OutputStream向服務(wù)器發(fā)送數(shù)據(jù),但在服務(wù)端程序中這個單字節(jié)的數(shù)據(jù)是和其它的普通數(shù)據(jù)混在一起的。因此,在服務(wù)端程序中并不知道由客戶端發(fā)過來的數(shù)據(jù)是由OutputStream還是由sendUrgentData發(fā)過來的。

http://www.cnblogs.com/biakia/p/4321800.html

總結(jié)

以上是生活随笔為你收集整理的java setsolinger_java socket 的参数选项解读(转)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 天天综合天天色 | 国产成人久久精品麻豆二区 | 香蕉视频在线视频 | 午夜视频在线免费播放 | 麻豆精品a∨在线观看 | 玖玖精品在线 | 丝袜美腿亚洲一区二区图片 | 日本欧美激情 | 偷拍亚洲| 看91| 狠狠干少妇 | 久久手机看片 | www黄在线观看 | 黄色av一区 | 色一情| 一区不卡在线观看 | 这里只有精品免费视频 | 亚洲综合图片区 | h部分肌肉警猛淫文 | 久久国产传媒 | 国产寡妇亲子伦一区二区三区四区 | 草草影院最新网址 | 国产又粗又猛又黄视频 | 国产美女又黄又爽又色视频免费 | 久久国产精品偷 | 亚洲AV无码成人精品国产一区 | 国产对白在线 | 一级艳片新婚之夜 | 被各种性器调教到哭vk | 日本一区二区在线免费观看 | 欧美成人三级在线 | 99re中文字幕 | 无码精品国产一区二区三区免费 | 久久黄色录像 | 国产三级在线观看 | www.夜夜爱 | 国产五月天婷婷 | 网站黄色在线观看 | 日韩综合一区二区 | 撕开少妇裙子猛然进入 | 精品一区二区三区国产 | 亚洲 欧美 中文字幕 | 日韩午夜免费 | 国内外成人在线视频 | 欧美岛国国产 | caopor超碰 | 国产精品丝袜黑色高跟 | 免费一级特黄特色毛片久久看 | 日韩成人三级 | 五月婷婷伊人网 | 色噜噜狠狠一区二区 | 精品久久在线观看 | 久久久久久久久精 | 亚洲欧美日韩综合 | 99在线免费 | 国产有码视频 | 毛片网在线 | 粗大挺进潘金莲身体在线播放 | 女同在线观看 | 性生活网址 | 成人福利小视频 | 无码内射中文字幕岛国片 | 毛片综合 | a片在线免费观看 | 欧美aaaa视频 | 777精品久无码人妻蜜桃 | 老牛影视av一区二区在线观看 | 欧美另类色 | yy6080午夜 | 免费观看在线观看 | 亚洲综合在线网 | 少妇人妻偷人精品一区二区 | 美女免费福利视频 | 97久久久久久 | 日日操夜夜草 | 亚洲天堂社区 | 一区二区三区福利视频 | 制服丝袜成人动漫 | 丰满人妻一区二区三区大胸 | 国产乱人乱偷精品视频 | 欧美一区二区三区的 | www日韩视频| 国产日产精品一区二区三区四区 | 国产91在线视频观看 | 国产自在线 | 亚洲色图 一区二区 | 99热这里只有精品1 亚洲人交配视频 | 一级黄色片免费看 | 国产一线二线在线观看 | 午夜免费网 | 欧美日韩综合视频 | 一级国产视频 | 国产成人区 | 中国一区二区视频 | 欧美精品99 | 快色在线观看 | 黄色片www| 国产女人在线视频 | 欧美乱色 |