我正在使用 java 的 socketio 和 netty,而且我对它们都是新手。
\n我的客户端代码如下所示。
\n<!DOCTYPE html>\n<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">\n<head>\n <title >webSocket test</title>\n <script src="http://code.jquery.com/jquery-1.12.4.min.js"></script>\n <script src="https://cdn.socket.io/3.1.3/socket.io.min.js" integrity="sha384-cPwlPLvBTa3sKAgddT6krw0cJat7egBga3DJepJyrLl4Q9/5WLra3rrnMcyTyOnh" crossorigin="anonymous"></script>\n < !-- New Bootstrap core CSS file-->\n <!-- Optional Bootstrap theme file (generally not necessary to import) -->\n <!- -jQuery file. Be sure to introduce before bootstrap.min.js -->\n\n <!-- The latest Bootstrap core JavaScript file-->\n <script type=" text/javascript">\n $(function(){\n /**\n * The socket.emit("event name", "parameter data") method of the\n front-end js is used when triggering the back-end …Run Code Online (Sandbox Code Playgroud) 我已经使用 Spring 框架和 Netty SocketIO 实现了一个 websocket 服务器。在开发过程中,我使用了主机地址,localhost服务器运行良好。
当我尝试将我的代码部署到 AWS 时,我将主机地址更改为我的实例的公共 IP 地址。但是我收到以下错误并且我无法启动我的服务器
Caused by: java.net.BindException: Can't assign requested address
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:433)
at sun.nio.ch.Net.bind(Net.java:425)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
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)
Run Code Online (Sandbox Code Playgroud)
如果我可以在 AWS 中为主机分配我的公共 IP 地址,那么我可以使用哪个 IP 地址来启动我的 Socket 服务器?