Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.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
Swift Vapor-创建web套接字_Swift_Vapor - Fatal编程技术网

Swift Vapor-创建web套接字

Swift Vapor-创建web套接字,swift,vapor,Swift,Vapor,我正在尝试使用Vapor创建一个小型聊天应用程序,但我被卡住了。我在ios上使用Socket.IO,我总是得到找不到的错误页面 你能指导我识别我的错误吗 蒸汽代码: drop.socket("ws") { req, ws in print("New WebSocket connected: \(ws)") // ping the socket to keep it open try background { while ws.state == .open { try? ws.ping()

我正在尝试使用Vapor创建一个小型聊天应用程序,但我被卡住了。我在ios上使用Socket.IO,我总是得到找不到的错误页面

你能指导我识别我的错误吗

蒸汽代码:

drop.socket("ws") { req, ws in
print("New WebSocket connected: \(ws)")

// ping the socket to keep it open
try background {
while ws.state == .open {
  try? ws.ping()
  drop.console.wait(seconds: 10) // every 10 seconds
}
}

ws.onText = { ws, text in
print("Text received: \(text)")

// reverse the characters and send back
let rev = String(text.characters.reversed())
try ws.send(rev)
}

ws.onClose = { ws, code, reason, clean in
print("Closed.")
}
}

drop.run()
在客户端:

func receiveMSGFromServer(){

let u = URL(string: "ws://localhost:8080/ws")
//"http://localhost:8080/"

let socket = SocketIOClient(socketURL: URL(string: "wss://localhost:8080/ws")!, config: [.log(true), .forcePolling(true)]) //SocketIOClient(socketURL: u!)

socket.emit("ws", ":emptyParam")

socket.on("ws") {data, ack in
  print("Message for you! \(data[0])")
 // ack("I got your message, and I'll send my response")
  socket.emit("response", "Hello!")
}

socket.connect()

}

看起来您正在
socketURL
中使用
wss

只有通过TLS(SSL)托管应用程序时,这才有效


尝试只使用
ws
或通过TLS托管应用程序。

看起来您正在
socketURL
中使用
wss

只有通过TLS(SSL)托管应用程序时,这才有效


尝试只使用
ws
或通过TLS托管应用程序。

我不确定socket io是否是通用的websocket库。我相信它的目的是与后端的专有套接字库进行通信。您可能想尝试红蜘蛛或其他与Vapor通信的方法。如果回答bellow有效,请将此问题标记为Resolved我在与SocketIOClient不工作时遇到问题。我试过红蜘蛛,它成功了。我不确定socket io是否是一个通用的websocket库。我相信它的目的是与后端的专有套接字库进行通信。您可能想尝试红蜘蛛或其他与Vapor通信的方法。如果回答bellow有效,请将此问题标记为Resolved我在与SocketIOClient不工作时遇到问题。我试过红蜘蛛,它成功了。