tidwall / SwiftWebSocket

Fast Websockets in Swift for iOS and OSX
MIT License
1.53k stars 244 forks source link

How to subscribe and listen to events? #131

Open VikranthKumar05 opened 6 years ago

VikranthKumar05 commented 6 years ago

Can anyone please share the code snippet of subscribing and listening to events?

iosparesh commented 3 years ago

I am also looking for same var request = URLRequest(url:url) request.method = .get do { let json = try JSONSerialization.data(withJSONObject: ["topic": "aws/subscribe", "content": ["topics":"aws/chat"]], options: .fragmentsAllowed) request.httpBody = json } catch { print("error") } socket = WebSocket(request: request) socket?.compression.on = true socket?.eventQueue = .main socket?.binaryType = .nsData socket?.delegate = self socket?.event.open = { print("opened") } socket?.event.error = { error in print("error (error)") } socket?.event.message = {(data) in print(data as? String ?? "") }