5 #include "IoTDeviceAddress.hpp"
9 // IoTUDP class for iotruntime
10 // Implemented based on IoTUDP.java that is used to wrap communication socket for UDP
12 // @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
18 // IoTUDP class properties
20 string strHostAddress;
29 IoTUDP(IoTDeviceAddress iotDevAdd) {
31 strHostAddress = iotDevAdd.getAddress();
32 iSrcPort = iotDevAdd.getSourcePortNumber();
33 iDstPort = iotDevAdd.getDestinationPortNumber();
35 socket = new UDPSocket(iSrcPort);
37 perror("IoTUDP: UDP socket isn't initialized!");
54 void sendData(const void* buffer, int bufferLen) {
56 unsigned short destinationPort = (unsigned short) iDstPort;
57 socket->sendTo(buffer, bufferLen, strHostAddress, destinationPort);
61 // Receive data packet
62 int receiveData(void* buffer, int iMaxDataLength) {
64 unsigned short destinationPort = (unsigned short) iDstPort;
65 return socket->recvFrom(buffer, iMaxDataLength, strHostAddress, destinationPort);