java.net.sockttimeout_Java Socket.getSoTimeout方法代码示例

import java.net.Socket; //导入方法依赖的package包/类

/**

* HandShake Constructor used by server side connection

*/

public HandShake(Socket sock, int timeout, DistributedSystem sys, Version clientVersion,

byte communicationMode) throws IOException, AuthenticationRequiredException {

this.clientVersion = clientVersion;

this.system = sys;

// SocketChannel sc = sock.getChannel();

/*

* if (sc != null) { } else

*/ {

int soTimeout = -1;

try {

soTimeout = sock.getSoTimeout();

sock.setSoTimeout(timeout);

InputStream is = sock.getInputStream();

int valRead = is.read();

// this.code = (byte)is.read();

if (valRead == -1) {

throw new EOFException(

LocalizedStrings.HandShake_HANDSHAKE_EOF_REACHED_BEFORE_CLIENT_CODE_COULD_BE_READ

.toLocalizedString());

}

this.code = (byte) valRead;

if (this.code != REPLY_OK) {

throw new IOException(

LocalizedStrings.HandShake_HANDSHAKE_REPLY_CODE_IS_NOT_OK.toLocalizedString());

}

try {

DataInputStream dis = new DataInputStream(is);

DataOutputStream dos = new DataOutputStream(sock.getOutputStream());

this.clientReadTimeout = dis.readInt();

if (clientVersion.compareTo(Version.CURRENT) < 0) {

// versioned streams allow object serialization code to deal with older clients

dis = new VersionedDataInputStream(dis, clientVersion);

dos = new VersionedDataOutputStream(dos, clientVersion);

}

this.id = ClientProxyMembershipID.readCanonicalized(dis);

// Note: credentials should always be the last piece in handshake for

// Diffie-Hellman key exchange to work

if (clientVersion.compareTo(Version.GFE_603) >= 0) {

setOverrides(new byte[] {dis.readByte()});

} else {

setClientConflation(dis.readByte());

}

// Hitesh

if (this.clientVersion.compareTo(Version.GFE_65) < 0

|| communicationMode == Acceptor.GATEWAY_TO_GATEWAY) {

this.credentials = readCredentials(dis, dos, sys);

} else {

this.credentials = this.readCredential(dis, dos, sys);

}

} catch (IOException ioe) {

this.code = -2;

throw ioe;

} catch (ClassNotFoundException cnfe) {

this.code = -3;

throw new IOException(

LocalizedStrings.HandShake_CLIENTPROXYMEMBERSHIPID_CLASS_COULD_NOT_BE_FOUND_WHILE_DESERIALIZING_THE_OBJECT

.toLocalizedString());

}

} finally {

if (soTimeout != -1) {

try {

sock.setSoTimeout(soTimeout);

} catch (IOException ignore) {

}

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值