Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法将红蜘蛛WebSocket连接到Java服务器套接字_Java_Swift_Sockets_Starscream - Fatal编程技术网

无法将红蜘蛛WebSocket连接到Java服务器套接字

无法将红蜘蛛WebSocket连接到Java服务器套接字,java,swift,sockets,starscream,Java,Swift,Sockets,Starscream,我为正在制作的应用程序设置了Java服务器。Java服务器在尝试连接时接收新客户端: //Continuously accept new user clients try(ServerSocket serverSocket = new ServerSocket(portNumber)){ while(!Thread.currentThread().isInterrupted()){ //I do some stuff here

我为正在制作的应用程序设置了Java服务器。Java服务器在尝试连接时接收新客户端:

//Continuously accept new user clients
    try(ServerSocket serverSocket = new ServerSocket(portNumber)){ 

        while(!Thread.currentThread().isInterrupted()){

            //I do some stuff here
            ...
            //Then accept the socket
            Socket s = serverSocket.accept();

            //Then I do stuff with s; the user is connected
            ...

        }

    } catch (IOException e) {
        System.err.println("Could not listen on port "+portNumber);
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
在Android上,我只使用Socket类,没有问题。它连接到AWS上运行在EC2上的Java服务器的端点,我没有问题。然而,就我所发现的iOS而言,第三方库是非常值得推荐的,目前我已经决定使用它

我无法让简单的连接示例与红蜘蛛github页面上的示例相匹配。有一些教程,比如用Node.js设置本地服务器,但我不想深入讨论,因为我已经有了一个“非常简单”的服务器

这是我的swift代码:

class ViewVontroller: UIViewController, WebSocketDelegate{
    var socket = WebSocket(url: URL(string: "ec2-12-345-678-910.compute-1.amazonaws.com/:4922/")!)

    override func viewDidLoad(){
        super.viewDidLoad()
        socket.delegate = self

        print("connecting")
        socket.connect()
        print("should've connected")
    }
    ... //The rest of the protocol is implemented below with simple print statements as the body
它输出:

connecting
should've connected
[timestamp/project name...] [] nw_connection_get_connected_socket_block_invoke 1 Connection has no connected handler
Websocket disconnected: The operation couldn't be completed. Operation timed out

从红蜘蛛WebSocket连接到Java服务器套接字是否存在某种问题?我读过一些关于其他人的案例中出现此类问题的信息,但我对套接字的底层实现几乎一无所知。

您的服务器似乎没有实现


WebSocket不仅仅是TCP连接;它使用特定的基于HTTP的握手,并向流中添加帧。这是可能的,但如果可能的话,我建议您改用库,因为确实有。

我刚刚开始浏览您的链接,但这就是我一直在寻找的路径。谢谢