last day (16 days later) » 

7:00 AM
0
Q: Swift: Receiving UDP packets from server on serial port monitor but not in ios app

LightI send UDP packets to a wifi module and receive them and i monitor them in serial port monitor successfully but unable to receive them in iOS app. I'm using Network Framework both for connecting and receive. The connection part works perfectly but when i set a listener to the port, and try to ge...

 
What output do you get from your app? Are you running on a simulator or real device? Does your module have the correct IP address destination for your app?
 
As i said sending works perfect and i see corresponding logs but i get nothing once out packets from module is starting to flood in and i tested both on simulator and real device. How should i check that if module has the correct IP or not?(although i think it does)
 
Do you want to receive packets from the device you are sending to or from any device. If the former then you need to receive on the connection in your connect stateUpdateHandler. If the latter then you need to receive on the connection password to the newConnectionHandler of your Listener
 
I only wanna receive from the device and i have set a listener to the exact port that i've sent the packet through that. isn't is correct?
 
No. A listener is for new incoming connections. You want to receive on the connection you established and sent on. Your packets will come from a random, high port. The device will send back to that high port.
 
7:00 AM
yeah i have seen it and tried but only send func called but not receive
 
You also need to confirm that your wifi device is correctly swapping the send & receive ports. Ie if it receives a packet in port “portUDP” and from port 12345 it needs to send its replies from “portUDP” and to 12345
 
yeah the device sends the packets back in correct port. I also added my serial port monitor output
did you see the image?
 
So you call your receive function after calling sendPaket and in the receive function you are calling receiveMessage on the connection you created in connect?
 
exactly
 
Hmm. Then I’m not sure. The code in my answer on the other question works.
You could use netcat to test your app and your device. jameshfisher.com/2018/03/04/create-udp-connection-with-netcat
 
7:15 AM
 class func receive()
    {
        print("Receive func got called")
        connection?.receiveMessage(completion:
        {
            (data, context, isComplete, error) in
            print("connection.receive func got called")
            if (isComplete)
            {
                print("receiving is complete!")
                if (data != nil)
                {
                    let backToString = String(decoding: data!, as: UTF8.self)
                    print("Received message: \(backToString)")
this is my receive func that only first print gets called
 

  last day (16 days later) »