天天看點

UDP(socket)接和資料案例封裝成C++代碼



配置qt下的pro檔案

編寫udp.h檔案

#ifndef

udp_h

#define

#ifdef

mylinux

#include

<sys/types.h>

<sys/socket.h>

<arpa/inet.h>

<unistd.h>

socket

int

#else

<winsock2.h>

#endif

class

myudp

{

private:

st;//類的内部成員一般是不暴露在類外部的

public:

myudp();

myudp(const

&it);

~myudp();

socket_bind(short

port);

socket_send(const

char

*ip,

const char

*buf,

int len);

socket_recv(char

int len,

char *srcip);

};

//

3.編寫udp.cpp

4.main.c的實作代碼

繼續閱讀