Switch UDP and TCP protocols with WiFly

Hi,

I am using a WiFly module & the WiflyHQ Library to send messages to a TCP server and a UDP server alternatively.
But I have some problem with switching protocols.
What I am trying to do is to alternate sending TCP messages and UDP messages.
0. Connect to a TCP server

  1. Send some TCP messages
  2. Switch protocol setting to use UDP.
  3. Send some UDP messages.

I have discovered that the change of protocol on the WiFly module is only active after rebooting the module.
And it takes too long for rebooting & rejoining the module.

Is there any better way to make switching the protocols?

Here’s the code excerpt.

    //Send TCP message first
     wifly.setIpProtocol(WIFLY_PROTOCOL_TCP);
     wifly.open("192.168.1.60",8042);
     wifly.println("sending TCP message.");
     wifly.close();
    //Switch to UDP protocol
     Wifly. setIpProtocol (WIFLY_PROTOCOL_UDP);
     wifly.setHose("192.168.1.60",8045);
     wifly.save();
     wifly.reboot();
     wifly.join();
   
     //Send UDP message
      wifly.println("sending UDP message.");

Any help&insights would be appreciated!

Thank You

TCP_UDPswitch.ino (2.37 KB)