1

I want to be able to have one ios-device that multiple ios-devices (is there any max?) are able to connect to and send data(a string in this case) to the first device.

I have tried this tutorial: http://www.raywenderlich.com/3932/networking-tutorial-for-ios-how-to-create-a-socket-based-iphone-app-and-server But I have a hard time understanding Objective-C

ntoonio
  • 3,024
  • 4
  • 24
  • 28
  • I am also on your way. I have succeded in sending messages to a server and could display those messages in Terminal. What is your status? –  Dec 19 '15 at 11:31
  • @Jess The same I think. I managed to send a string to a server, and the server send a string to any connected device! You can checkout my GitHub repository where I'm using it http://github.com/Totoajax/Alfons – ntoonio Apr 09 '16 at 10:30
  • I checked your git project. .xcodeproj file is missing. –  Apr 11 '16 at 04:12
  • @Jess I've uploaded it now :) – ntoonio Apr 11 '16 at 06:29
  • Good work done. I did the same using NSStream and swift. –  Apr 11 '16 at 06:50

1 Answers1

2

Actually, for swift it will be the same as for objC. All you need is to port syntax from objC to swift:

func initNetworkCommunication() {
    var readStream : Unmanaged<CFReadStream>?;
    var writeStream : Unmanaged<CFWriteStream>?;
    CFStreamCreatePairWithSocketToHost(nil, "localhost", 80, &readStream, &writeStream);
    if let read = readStream {
        inputStream = readStream!.takeUnretainedValue()
    }
    if let write = writeStream {
       outputStream = writeStream!.takeUnretainedValue()
    }
}

and so on...