Closed just4give closed 9 years ago
try another port, 8081 used by tomcat shutdown service
I tried several different ports on mac such as 4000, 7777, 8888 and I got exact same error all the time. Above WebSocketManager class is loaded by spring container at startup. Wondering if this is related to running SocketIO inside Tomcat7. Can anyone please direct me to any sample code base which runs on Tomcat7 ?
may be your ports under the firewall?
Firewall is turned off on my system. Also when I run the server from standalone java class, SocketIO server starts up successfully. Problem is while running within tomcat7. Any clue ?
Below is the standalone program which runs properly.
public class WebSocketApplication {
public static void main(String[] args) throws InterruptedException {
Configuration config = new Configuration();
config.setHostname("localhost");
config.setPort(7777);
SocketConfig socketConfig = new SocketConfig();
socketConfig.setReuseAddress(true);
config.setSocketConfig(socketConfig);
final SocketIOServer server = new SocketIOServer(config);
server.addEventListener("chatevent", ChatObject.class,
new DataListener<ChatObject>() {
public void onData(SocketIOClient client, ChatObject data,
AckRequest ackRequest) {
System.out.println("on data");
server.getBroadcastOperations().sendEvent("chatevent",
data);
}
});
System.out.println("Starting SocketIO server");
server.start();
Thread.sleep(30*1000);
System.out.println("Stopping SocketIO server");
server.stop();
}
}
I use netty-socketio in production with tomcat 7 and it works without any problem. No any port binding issues.
Did you make any changes in Tomcat configuration? If possible, can you please share the working code?
no, i didn't change ports in tomcat. Tomcat uses 8080 port and socketio 7272 or 9292
@just4give I have the same issue.Do you have the answer about this? Sorry for my English.
@xianwei I never got it working after couple of try. I have to look back.
I am trying to run SocketIO server inside Tomcat. I am not sure if this the right way to do that. But when application is deployed, I am seeing "Address already in user" exception. Below is my code.
@Component public class WebSocketManager {
}
Error Stack
java.net.BindException: Address already in use at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Net.java:444) at sun.nio.ch.Net.bind(Net.java:436) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:125) at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:484) at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1080) at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:430) at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:415) at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:903) at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:197) at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:350) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:380) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357) at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116) at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) at java.lang.Thread.run(Thread.java:745)