udp_teste.cpp 939 Bytes
#include "jsocket.h"
#include "jdatagramsocket.h"

#include <iostream>
#include <stdexcept>

#include <fcntl.h>

using namespace jsocket;


int streamer() 
{
	char buffer[188];
	
	int size;
	
	try {
		DatagramSocket c("10.0.0.1", 3200);
		
		int fd = open("evanescence.mpg", O_RDONLY);

		if (fd <= 2) {
			return -1;
		}

		while ((size = read(fd, buffer, 1500)) != 0) {
			c.Send(buffer, size);
			usleep(3334);
		}
		
		c.Close();
	} catch (std::runtime_error &e) {
		std::cout << "error " << e.what() << std::endl;
	}

	return 0;
}

int simple()
{
	char buffer[] = "Jefferson eh o que ah !";
	
	try {
		DatagramSocket c("localhost", 3200);
	
		std::ostream &o = c.GetOutputStream();
		
		o << buffer << std::endl;
		
		c.Close();
	} catch (std::runtime_error &e) {
		std::cout << "error " << e.what() << std::endl;
	}

	return 0;
}

int main()
{
	simple();

	return 0;
}