+ wxString hostname = wxGetTextFromUser
+ (
+ "Enter the address of the wxSocket demo server:",
+ "UDP peer",
+ "localhost"
+ );
+ if ( hostname.empty() )
+ return;
+
+ TestLogger logtest("UDP");
+
+ wxIPV4address addrLocal;
+ addrLocal.Hostname();
+ wxDatagramSocket sock(addrLocal);
+ if ( !sock.IsOk() )
+ {
+ wxLogMessage("ERROR: failed to create UDP socket");
+ return;
+ }
+
+ wxLogMessage("Created UDP socket at %s:%u",
+ addrLocal.IPAddress(), addrLocal.Service());
+
+ wxIPV4address addrPeer;
+ addrPeer.Hostname(hostname);
+ addrPeer.Service(3000);
+
+ wxLogMessage("Testing UDP with peer at %s:%u",
+ addrPeer.IPAddress(), addrPeer.Service());
+
+ char buf[] = "Uryyb sebz pyvrag!";
+ if ( sock.SendTo(addrPeer, buf, sizeof(buf)).LastCount() != sizeof(buf) )
+ {
+ wxLogMessage("ERROR: failed to send data");
+ return;
+ }
+
+ if ( sock.RecvFrom(addrPeer, buf, sizeof(buf)).LastCount() != sizeof(buf) )
+ {
+ wxLogMessage("ERROR: failed to receive data");
+ return;
+ }
+
+ wxLogMessage("Received \"%s\" from %s:%u.",
+ wxString::From8BitData(buf, sock.LastCount()),
+ addrPeer.IPAddress(), addrPeer.Service());