You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
987 B
56 lines
987 B
|
|
#ifndef _SP_UDP_H_
|
|
#define _SP_UDP_H_
|
|
|
|
#include <time.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <netdb.h>
|
|
#include <errno.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/wait.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
|
|
#include <string>
|
|
|
|
#include "config.h"
|
|
|
|
using namespace std;
|
|
|
|
#define NET_HOSTLEN 128
|
|
#define NET_PORTLEN 6
|
|
#define NET_BUFFERSIZE 1024
|
|
|
|
|
|
class UDPConnection {
|
|
private:
|
|
string port;
|
|
int sock;
|
|
size_t readcnt;
|
|
size_t writecnt;
|
|
public:
|
|
UDPConnection();
|
|
~UDPConnection();
|
|
|
|
int Listen(int port);
|
|
int Listen(string port);
|
|
|
|
long int ReadTimeout(string *srcaddr, char *buffer, long int len, int timeout);
|
|
long int Read(string *srcaddr, char *buffer, long int len);
|
|
long int Send(string destaddr, char *buffer, long int len);
|
|
|
|
void Close();
|
|
int isListen();
|
|
int isData(int timeout); // timeout in ms;
|
|
|
|
int getSocket() { return sock; };
|
|
void setSocket(int s);
|
|
};
|
|
|
|
#endif
|