I have this code in my C program.
Now I'm coding on Qt and want to remake this to QUdpSocket.
Is it really?

algorythm are here:
we have ip and port of udp server,
make data and send it to ip and port of server,
and waiting answer...
i can't use bind(ip,port), i don't know recv port, its generates the socket subsystem, and server get it from incoming datagramm.
i know Qudpsocket needs to be bind on fixed port.
Qudpsocket is unusable at my use?

Qt Code:
  1. unsigned char sendbuf[11] = "";
  2. unsigned char recvbuf[DEFAULT_BUFLEN] = "";
  3.  
  4. SOCKET S;
  5. sockaddr_in SA;
  6. int SA_Size = sizeof(SA);
  7.  
  8. int iResult;
  9. int recvbuflen = DEFAULT_BUFLEN;
  10.  
  11. WSAData WSData;
  12. WSAStartup(0x101,&WSData);
  13.  
  14. S = socket(AF_INET,SOCK_DGRAM,0);
  15.  
  16. SA.sin_family=AF_INET;
  17. SA.sin_port=htons(2323);
  18. SA.sin_addr.S_un.S_addr=inet_addr(_ip.c_str());
  19.  
  20. //filling sendbuf here..
  21.  
  22. //sending sendbuf
  23. sendto(S, (char*)sendbuf,sizeof(sendbuf), 0,(struct sockaddr *)&SA, sizeof(SA))
  24.  
  25. //receiving answer
  26. fd_set rfds;
  27. struct timeval tv;
  28. tv.tv_sec = _timeout;
  29. tv.tv_usec = 0;
  30. FD_ZERO(&rfds);
  31. FD_SET(S,&rfds);
  32. if (select((int)S+1, &rfds, NULL, NULL, &tv) > 0)
  33. {
  34. //getting data from
  35. iResult=recvfrom(S, (char*)recvbuf, recvbuflen, 0, (struct sockaddr *)&SA, &SA_Size);
  36. closesocket(S);
  37. WSACleanup();
  38. }
  39. ...
To copy to clipboard, switch view to plain text mode