Skip to content

Instantly share code, notes, and snippets.

@jamlfy
Created April 12, 2017 03:03
Show Gist options
  • Save jamlfy/cf12935b6ead97b36d1907fed3152a1b to your computer and use it in GitHub Desktop.
Save jamlfy/cf12935b6ead97b36d1907fed3152a1b to your computer and use it in GitHub Desktop.
import UIkit
import WebSocket
...
// Mobile
socket = WebSocket(url: URL(string: "ws://localhost:8080/")!)
//websocketDidConnect
socket.onConnect = {
print("websocket is connected")
}
//websocketDidDisconnect
socket.onDisconnect = { (error: NSError?) in
print("websocket is disconnected: \(error?.localizedDescription)")
}
//websocketDidReceiveMessage
socket.onText = { (text: String) in
print("got some text: \(text)")
}
//websocketDidReceiveData
socket.onData = { (data: Data) in
print("got some data: \(data.count)")
}
//you could do onPong as well.
socket.connect()
socket.write(string: "Hi Server!");
// Console IOS
got some text: Hi Server!
// Server Java
@overwite function (String: data) ReturnType {
print(data);
socket.write(data);
}
Console SERVER
Hi Server!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment