Created
April 12, 2017 03:03
-
-
Save jamlfy/cf12935b6ead97b36d1907fed3152a1b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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