Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
    Bookmark Topic Watch Topic
  • New Topic

Nonblocking socket question of client'sprogram ,help!!!!!!

 
jgm jinggm
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Report post to moderator
Nonblocking socket client'sprogram like this:
SocketChannel m_oCltChannel = null;
Selector m_oReadSelector = null;
Selector m_oWriteSelector = null;
m_oReadSelector = Selector.open();
m_oWriteSelector = Selector.open();
m_oCltChannel = SocketChannel.open();

m_oCltChannel.configureBlocking(false);
InetSocketAddress isa = new InetSocketAddress(m_sServerHost, m_iPort);
m_oCltChannel.connect(isa);
m_oCltChannel.register(m_oReadSelector,SelectionKey.OP_CONNECT | SelectionKey.OP_READ );
m_oClt.m_oCltChannel.register(m_oWriteSelector,SelectionKey.OP_WRITE );
while(true){
if(m_oReadSelector.select()>0){
Set oReadKeys = m_oReadSelector.selectedKeys();
Iterator i = oReadKeys.iterator();
while(i.hasNext()){
SelectionKey tmp = (SelectionKey)i.next();
i.remove();
if (tmp.isConnectable()){
/*why come here always ???*/
if (((SocketChannel)tmp.channel()).isConnectionPending()){
while(!((SocketChannel)tmp.channel()).finishConnecta(){}
}
if (tmp.isReadable()){
/*why dont come here always ???*/
}

}
}
if(m_oWriteSelector.select()>0){
Set oWriteKeys = m_oWriteSelector.selectedKeys();
Iterator i = oWriteKeys.iterator();
while(i.hasNext()){
SelectionKey tmp = (SelectionKey)i.next();
i.remove();
if (tmp.isWriteable()){
/*why dont come here always ???*/
}
}
}
}
if i use blocking socket, this while do well work .what happend???
 
Marilyn de Queiroz
Sheriff
Posts: 9079
12
  • Mark post as helpful
  • send pies
  • Report post to moderator
duplicate in the IO forum
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!