请大家看下面的代码:
len = is.read(gData);
这句代码会阻塞在这里,用了上面红色标出的代码后,能不能实现,超过5秒没反应后,read就不阻塞,而向下执行代码!
try
{
int len = 0;
sc = (SocketConnection) Connector.open("socket://100.42.25.3:885");
is = sc.openInputStream();
os = sc.openOutputStream();
sc.setSocketOption( SocketConnection.LINGER, 5);
pmm.gDataBuf = null;
sender = new Sender(os);
sender.send(pmm.gStringReq);
// Loop forever, receiving data
gData = new byte[pmm.BUF_LENGTH];
currentIndex = 0;
gBuf = new byte[50*1024];
while (!pmm.bStopConnect)
{
len = is.read(gData);
System.arraycopy(gData,0,gBuf,currentIndex,len);
currentIndex += len;
len = is.read(gData);
这句代码会阻塞在这里,用了上面红色标出的代码后,能不能实现,超过5秒没反应后,read就不阻塞,而向下执行代码!
try
{
int len = 0;
sc = (SocketConnection) Connector.open("socket://100.42.25.3:885");
is = sc.openInputStream();
os = sc.openOutputStream();
sc.setSocketOption( SocketConnection.LINGER, 5);
pmm.gDataBuf = null;
sender = new Sender(os);
sender.send(pmm.gStringReq);
// Loop forever, receiving data
gData = new byte[pmm.BUF_LENGTH];
currentIndex = 0;
gBuf = new byte[50*1024];
while (!pmm.bStopConnect)
{
len = is.read(gData);
System.arraycopy(gData,0,gBuf,currentIndex,len);
currentIndex += len;