1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include "UDPsocket.h"
#include "NetworkBox.h"
using namespace std;
int main(int argc,char **argv)
{
UDPsocket server;
UDPsocket client;
int sdServ = server.Open(12345);
int sdClient = client.Connect("127.0.0.1",12345);
NetworkBox from;
string msg = "HELLO 23456";
//initialization of file descriptor list
fd_set fd_supervised;
fd_set fd_ping;
while(1)
{
FD_ZERO(&fd_supervised);
FD_SET(sdServ,&fd_supervised);
FD_ZERO(&fd_ping);
FD_SET(sdClient,&fd_ping);
select(FD_SETSIZE, &fd_supervised, &fd_ping, NULL, NULL);
//retrieve the message from the server
if(FD_ISSET(sdServ, &fd_supervised))
{
server.RecvFrom(msg,from);
cout << "recu : " << msg << "\n\n" << endl;
}
//supervise sd writing
if(FD_ISSET(sdClient, &fd_ping))
{
sleep(10);
client.SendTo(msg,"127.0.0.1",12345);
}
}//while
}//main() |
Partager