Example #1
0
void* ascoltatore(void *p) {	
	SocketUDP *udp = (SocketUDP*)p;
	
	Address *mittente = new Address();
	
	char *dato, *da;
		
	for( ; ; ) {
		dato = udp->ricevi(mittente);
		
		if(dato) {
			da = mittente->toString();
			
			printf("%s %s\n", da, dato);
			
			free(da);
			free(dato);
		}
		else {
			printf(ERRORE_RICEZIONE"\n");
		}
	}
	
	delete mittente;
}
Example #2
0
TEST_F(SocketUDPTest, Test)
{
    SocketUDP* socket;
    ASSERT_NO_THROW(socket = new SocketUDP());

    ASSERT_EQ(E_OK, socket->openAsReceiver("239.99.99.99", 12000, false));

    system("pause");

    ASSERT_EQ(E_OK, socket->close());
    delete socket;
}
Example #3
0
int main(int argc, char *argv[]) {
	SocketUDP *udp;
	
	pthread_t ascolta;
	
	if(argc != 2) {
		printf("USAGE: %s PORT\n", argv[0]);
		return -1;
	}
	
	broadcast_port = atoi(argv[1]);
	
	udp = new SocketUDP(strdup(MY_ADDR), broadcast_port);
	udp->enableBroadcast();	

	pthread_create(&ascolta, NULL, ascoltatore, (void*)udp);
	
	lancia_shell(udp);
	
	delete udp;
}
Example #4
0
int main(int argc, char* argv[]){
		int port;
		SocketUDP* mioSocket;
		Address* dest;
		char* ip;
		char* msg;
		
		if(argc!=3){
			printf("USAGE %s IP PORT MESSAGE\n", argv[0]);
			return(-1);
		}
		
		ip = argv[1];
		port = atoi(argv[2]);
		msg = argv[3];
		
		mioSocket = new SocketUDP();
		dest = new Address(ip, port);
		mioSocket->invia(*dest, msg);
		printf("[%s : %d] %s\n", ip, port, msg);
		//printf("%s\n", strerror(errno));
}
Example #5
0
void* srv(void* p){
		SocketUDP* mioSocket;
		Address* mit;
		char* msg;
		char ip[]={"0.0.0.0"};
		int port;
		
		port = *(int*)p;
		mioSocket = new SocketUDP(ip, port, true);
		
		while(1){		
			mit = new Address();
			msg = mioSocket->ricevi(mit);
			if(msg){
				printf("%s", msg);
				fflush(stdout);	
			}
			mit->~Address();
			free(msg);
		}
		
		mioSocket->~SocketUDP();
}