Reputation: 823
I am trying to make a WebSocket connection between iOS and server(SpringBoot). From the server side, we are using the WebSocket connection like this.
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker(URLMapping.WS_SEND);
config.setApplicationDestinationPrefixes(URLMapping.WS_PREFIX);
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/api/v1/transactionSocket").setAllowedOrigins("*").withSockJS();
}
}
In IOS, I have used StompClient library for making the WebSocket connection.
func makeConnection() {
let client = StompClient(url: URL(string: "/api/v1/transactionSocket")!)
client.delegate = self
client.connect()
}
func disconnectConnection() {
client.disconnect()
print("Disconnecting :\(client)")
}
func stompClientDidConnected(_ client: StompClient) {
print("Stomp got connected: \(client) .... \(client.isConnected)")
// client.subscribe("API")
}
func stompClient(_ client: StompClient, didErrorOccurred error: NSError) {
print("Stomp Error occures \(client) errror: \(error)")
}
func stompClient(_ client: StompClient, didReceivedData data: Data, fromDestination destination: String) {
print("Cliemt: \(client) Data: \(data) destination: \(destination)")
}
On running up neither connection is been made nor 'stompClientDidConnected' delegate method is been called.
I haven't used WebSocket so much. So can't able to understand what the reason is. Any help will be appreciated.
Thanks
Upvotes: 2
Views: 1215
Reputation: 527
You can use StopmClientLib
to make socket connection,also it has the subscribe method.
https://github.com/wrathchaos/StompClientLib
Upvotes: 3