我正在使用红蜘蛛打开一个websocket。问题是它不能在localhost或服务器上连接。
var socket = WebSocket(url: NSURL(string: "ws://localhost:8080/")!)
self.socket.voipEnabled = true;
socket.delegate = self
socket.connect()
func websocketDidConnect(ws: WebSocket) {
print("websocket is connected")
}
func websocketDidDisconnect(ws: WebSocket, error: NSError?) {
print("websocket is disconnected: \(error?.localizedDescription)")
}
func websocketDidReceiveMessage(ws: WebSocket, text: String) {
print("Received text: \(text)")
}
func websocketDidReceiveData(ws: WebSocket, data: NSData) {
print("Received data: \(data.length)")
}
func websocketDidReceivePong(socket: WebSocket) {
print("Got pong!")
}
@IBAction func writeText(sender: UIBarButtonItem) {
socket.writeString("hello there!")
}
答案 0 :(得分:0)
一旦我添加了self.socket.selfSignedSSL = true;
,它就开始连接了