This is example for emulating my situation
When I comment while clause, then application do not hang up.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.mina.example.chat;
import java.net.BindException;
import java.net.InetSocketAddress;
import org.apache.mina.common.DefaultIoFilterChainBuilder;
import org.apache.mina.common.IoAcceptor;
import org.apache.mina.common.IoAcceptorConfig;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.SocketAcceptor;
import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
/**
* (<b>Entry point</b>) Chat server
*
* @author The Apache Directory Project ([email protected])
* @version $Rev$, $Date$
*/
public class Main {
/** Choose your favorite port number. */
private static final int PORT = 1234;
/** Set this to true if you want to make the server SSL */
private static final boolean USE_SSL = false;
public static void main(String[] args) throws Exception {
IoAcceptor acceptor = new SocketAcceptor();
IoAcceptorConfig config = new SocketAcceptorConfig();
DefaultIoFilterChainBuilder chain = config.getFilterChain();
chain.addLast("codec", new ProtocolCodecFilter(
new TextLineCodecFactory()));
InetSocketAddress socketAddress = new InetSocketAddress("localhost111",
PORT);
System.out.println("Acceptor managing socket? "
+ acceptor.isManaged(socketAddress));
int bindNumber = 0;
int bindTimeout = 10;
while (!acceptor.isManaged(socketAddress)) {
try {
acceptor.bind(socketAddress, new ChatProtocolHandler(), config);
System.out.println("Socket Address: " + socketAddress);
} catch (BindException e) {
if (bindTimeout<= 0) {
Thread.sleep(1000);
} else if (bindTimeout> bindNumber) {
Thread.sleep(1000);
} else {
throw e;
}
bindNumber++;
} catch (Exception e) {
System.out.println("Can't connect to " + socketAddress + e);
throw new Exception("Can't connect to " + socketAddress, e);
} catch (Throwable e) {
System.out.println("Error connecting to " + socketAddress + e);
throw new Exception("Can't connect to " + socketAddress, e);
}
}
System.out.println("++++++++++++++++++++++++++");
System.out.println("Acceptor managing socket? "
+ acceptor.isManaged(socketAddress));
System.out.println("Listening on port " + PORT);
}
}
----- Original Message -----
From: "Emmanuel Lécharny"<[email protected]>
To: "Sergiy Mamit'ko"<[email protected]>
Sent: Friday, August 06, 2010 10:36 AM
Subject: Re: Error in bind
On 8/6/10 1:12 AM, Sergiy Mamit'ko wrote:
I cannot switch right now to MINA 2.0.0-RC1
Anyway, I am using jdk 1.5 and OS is WinXP and Unix.
basically, the cause is that the address is unesolved (localhost111 is not
found). I guess you knew that. Now, are you catching the exception when
you do a bind ? Do you process it ? If you don't, obviously, everything
will hang.
Can you post the part of the code where you bind the acceptor ?
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com