Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __INET_UDPSOCKET_H
00020 #define __INET_UDPSOCKET_H
00021
00022 #include <omnetpp.h>
00023 #include "UDPControlInfo_m.h"
00024
00025
00098 class INET_API UDPSocket
00099 {
00100 public:
00109 class CallbackInterface
00110 {
00111 public:
00112 virtual ~CallbackInterface() {}
00113 virtual void socketDatagramArrived(int sockId, void *yourPtr, cMessage *msg, UDPControlInfo *ctrl) = 0;
00114 virtual void socketPeerClosed(int sockId, void *yourPtr) {}
00115 };
00116
00117 enum State {NOT_BOUND, BOUND};
00118
00119 protected:
00120 int sockId;
00121 int usrId;
00122 int sockstate;
00123
00124 IPvXAddress localAddr;
00125 int localPrt;
00126 IPvXAddress remoteAddr;
00127 int remotePrt;
00128 int mcastIfaceId;
00129
00130 CallbackInterface *cb;
00131 void *yourPtr;
00132
00133 cGate *gateToUdp;
00134
00135 protected:
00136 void sendToUDP(cMessage *msg);
00137
00138 public:
00143 UDPSocket();
00144
00148 ~UDPSocket() {}
00149
00153 int getSocketId() const {return sockId;}
00154
00159 void setUserId(int userId);
00160
00164 int getUserId() const {return usrId;}
00165
00171 int getState() {return sockstate;}
00172
00176 static const char *stateName(int state);
00177
00181 static int generateSocketId();
00182
00185 IPvXAddress getLocalAddress() {return localAddr;}
00186 int getLocalPort() {return localPrt;}
00188
00191
00196 void setOutputGate(cGate *toUdp) {gateToUdp = toUdp;}
00197
00201 void bind(int localPort);
00202
00207 void bind(IPvXAddress localAddr, int localPort);
00208
00214 void connect(IPvXAddress remoteAddr, int remotePort);
00215
00221 void setMulticastInterfaceId(int interfaceId) {mcastIfaceId = interfaceId;}
00222
00226 int getMulticastInterfaceId() const {return mcastIfaceId;}
00227
00231 void sendTo(cMessage *msg, IPvXAddress destAddr, int destPort);
00232
00237 void send(cMessage *msg);
00238
00242 void close();
00244
00252 bool belongsToSocket(cMessage *msg);
00253
00259 static bool belongsToAnyUDPSocket(cMessage *msg);
00260
00282 void setCallbackObject(CallbackInterface *cb, void *yourPtr=NULL);
00283
00294 void processMessage(cMessage *msg);
00296 };
00297
00298 #endif
00299
00300