socket.io-client-swift icon indicating copy to clipboard operation
socket.io-client-swift copied to clipboard

Cross Platform Connection Issue

Open nhjariwala opened this issue 10 years ago • 3 comments

First of all thanks a lot for great library and lot of hard work. I want to create socket communication with Client (Mobile Application - Android and iOS) and Server (CapeSoft NetTalk Software).

CapeSoft NetTalk

nettalkdemo

In which NetSimple Object there is Server utility. It looks like below image

serverdemo

I want to send data and receive data between my Client (i.e iOS application) and Server but I am not able to do so. I am able to send data from my iOS app to socket.io server using below code

SocketIOManager

class SocketIOManager: NSObject {
    static let sharedInstance = SocketIOManager()

    var socket: SocketIOClient = SocketIOClient(socketURL: NSURL(string: "http://Url:Port")!)

    override init() {
        super.init()
    }

    func establishConnection() {
        socket.connect()
    }
    func sendMessage(user: String) {
         socket.emit("connectUser", user)
    }
    func closeConnection() {
        socket.disconnect()
    }
}

ViewController

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
     }
     override func didReceiveMemoryWarning() {
         super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
     }

     @IBAction func btnConnect(sender: UIButton) {  
         SocketIOManager.sharedInstance.establishConnection()
     }

     @IBAction func btnDisconnect(sender: UIButton) {
         SocketIOManager.sharedInstance.closeConnection()
     }

     @IBAction func btnMsg(sender: UIButton) {
         SocketIOManager.sharedInstance.sendMessage(txtInput.text!)
     }
}

Server

    var app = require('express')();
    var http = require('http').Server(app);
    var io = require('socket.io')(http);
    http.listen(Port, function(){
      console.log('Listening on *:Port');
    });
       io.on('connection', function(clientSocket){
       console.log('connected');
       clientSocket.on('disconnect', function(){
              console.log('disconnected');
        }); 
            var clientNickname;
         clientSocket.on("connectUser", function(clientNickname) {
          var message = "User " + clientNickname + " was connected.";
          console.log(message);
         });
    });

Above code works fine but I am not able to communicate with CapeSoft NetTalk Server(i.e shown on Image above).

Can anyone please help ?

nhjariwala avatar Aug 31 '16 07:08 nhjariwala

What is a nettalk server? Does it use socket.io? This library only connects to socket.io servers.

nuclearace avatar Aug 31 '16 21:08 nuclearace

@nuclearace Thanks for your response. NO Nettalk Server doesn't used socket.io. Is there any cross platform client library available for Server that don't use socket.io ? Sorry for bothering you.

nhjariwala avatar Sep 01 '16 03:09 nhjariwala

What do you mean server? An http client? WebSocket client? If you just want to interface with HTTP just use NSURLSession. Starscream is good if you want a WebSocket client.

nuclearace avatar Sep 01 '16 11:09 nuclearace