2

I have problem with receiving messages on specific port. Sending is working fine.

The code looks like that :

import Foundation
import CocoaAsyncSocket


class InSocket: NSObject, GCDAsyncUdpSocketDelegate {

//let IP = "192.168.1.196"
let PORT:UInt16 = 14000
var isocket:GCDAsyncUdpSocket!

override init(){
    super.init()
    setupConnection()
}

func setupConnection(){

    isocket = GCDAsyncUdpSocket(delegate: self, delegateQueue: DispatchQueue.main)
    do{
        try isocket.bind(toPort:PORT)
        try isocket.beginReceiving()
      } catch {print("ErrorReceive")}
}


func udpSocket(sock: GCDAsyncUdpSocket!, didReceiveData data: NSData, fromAddress address: NSData!, withFilterContext filterContext: AnyObject!) {
    let str = NSString(data: data as Data, encoding: String.Encoding.ascii.rawValue)
    print(str)

}
}

I see in network statistics that application is receiving packets: Packets

But I don't see anything in a console. Some ideas ?

Wisniatt
  • 21
  • 5

1 Answers1

0

Add before delegate function: func udpSocket(....) that attribute

@objc(udpSocket:didReceiveData:fromAddress:withFilterContext:)

XCode 8 will issue a warning, but do not pay attention, UDP packets will arrive.

mea405
  • 3
  • 2