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
21 string strHostAddress;
30 IoTUDP(IoTDeviceAddress* iotDevAdd) {
32 strHostAddress = iotDevAdd->getAddress();
33 iSrcPort = iotDevAdd->getSourcePortNumber();
34 iDstPort = iotDevAdd->getDestinationPortNumber();
37 socket = new UDPSocket(iSrcPort);
39 perror("IoTUDP: UDP socket isn't initialized!");
55 string getHostAddress() {
56 return strHostAddress;
65 int getDestinationPort() {
70 void setTimeOut(int interval) {
77 void sendData(const void* buffer, int bufferLen) {
78 unsigned short destinationPort = (unsigned short) iDstPort;
79 socket->sendTo(buffer, bufferLen, strHostAddress, destinationPort);
83 // Receive data packet
84 int receiveData(void* buffer, int iMaxDataLength) {
85 unsigned short destinationPort = (unsigned short) iDstPort;
86 //return socket->recvFrom(buffer, iMaxDataLength, strHostAddress, destinationPort);
87 return socket->recvFrom(buffer, iMaxDataLength, strHostAddress, destinationPort, timeOut);