Ejemplo n.º 1
0
void CTunnelingConnection::HandleDisconnectRequest(unsigned char* buffer)
{	
	CDisconnectRequest dis_req(buffer);
	if(dis_req.GetChannelID() != _state._channelid){
		return;
	}

	CDisconnectResponse dis_resp(_state._channelid,E_NO_ERROR);
	unsigned char buf[256];
	dis_resp.FillBuffer(buf,256);
	UDPSocket sock;

	LOG_DEBUG("[Send] [BUS] [Disconnect Response]");
	
	sock.SendTo(buf,dis_resp.GetTotalSize(),_device_control_address,_device_control_port);
	
	_heartbeat->Close();

	JTCSynchronized s(*this);
        _state._channelid = 0;
        _state._recv_sequence = 0;
        _state._send_sequence = 0;

        SetStatusDisconnected();
}
Ejemplo n.º 2
0
/**
 * Send an RDM Request.
 * This packs the data into a ACN structure and sends it.
 */
bool SimpleE133Controller::SendRequest(const UID &uid,
                                       uint16_t endpoint,
                                       RDMRequest *raw_request) {
  auto_ptr<RDMRequest> request(raw_request);

  IPV4Address *target_address = ola::STLFind(&m_uid_to_ip, uid);
  if (!target_address) {
    OLA_WARN << "UID " << uid << " not found";
    return false;
  }

  IPV4SocketAddress target(*target_address, E133_PORT);
  OLA_INFO << "Sending to " << target << "/" << uid << "/" << endpoint;

  // Build the E1.33 packet.
  IOStack packet(m_message_builder.pool());
  RDMCommandSerializer::Write(*request, &packet);
  RDMPDU::PrependPDU(&packet);
  m_message_builder.BuildUDPRootE133(
      &packet, ola::acn::VECTOR_FRAMING_RDMNET, 0, endpoint);

  // Send the packet
  m_udp_socket.SendTo(&packet, target);
  if (!packet.Empty()) {
    return false;
  }

  return true;
}
Ejemplo n.º 3
0
int client_main(int argc, char *argv[])
{
	if ((argc < 3) || (argc > 4))
	{   // Test for correct number of arguments
		std::cerr << "Usage: " << argv[0]
			<< " <Server> <Echo String> [<Server Port>]\n";
		exit(1);
	}

	std::string servAddress = argv[1];             // First arg: server address
	char* echoString = argv[2];               // Second arg: string to echo
	int echoStringLen = strlen(echoString);   // Length of string to echo
	if (echoStringLen > ECHOMAX)
	{    // Check input length
		std::cerr << "Echo string too long" << std::endl;
		exit(1);
	}
	unsigned short echoServPort = Socket::ResolveService(
		(argc == 4) ? argv[3] : "echo", "udp");

	try
	{
		UDPSocket sock;

		// Send the string to the server
		sock.SendTo(echoString, echoStringLen, servAddress, echoServPort);

		// Receive a response
		char echoBuffer[ECHOMAX + 1];       // Buffer for echoed string + \0
		int respStringLen;                  // Length of received response
		if ((respStringLen = sock.Receive(echoBuffer, ECHOMAX)) != echoStringLen)
		{
			std::cerr << "Unable to receive" << std::endl;
			exit(1);
		}

		echoBuffer[respStringLen] = '\0';             // Terminate the string!
		std::cout << "Received: " << echoBuffer << std::endl;   // Print the echoed arg

													  // Destructor closes the socket

	}
	catch (SocketException &e)
	{
		std::cerr << e.what() << std::endl;
		exit(1);
	}

	return 0;
}
Ejemplo n.º 4
0
void Cliente(std::string direccionDestino)
{
	UDPSocket udpSocket;
	SocketAddress saDestino;
	saDestino.SetAddress(direccionDestino);
	udpSocket.NonBlocking(true);
	while (true)
	{
		char datos[1300];
		int len = StringTools::PideDatosTeclado(datos);

		int bytesSend = udpSocket.SendTo(datos, len, saDestino);
		if (bytesSend > 0)
		{
			if (strcmp(datos, "exit") == 0)
			{
				break;
			}
		}
	}
}
Ejemplo n.º 5
0
/*
 * Send a packet
 */
bool SandNetNode::SendPacket(const sandnet_packet &packet,
                             unsigned int size,
                             bool is_control) {
  UDPSocket *socket;
  if (is_control)
    socket = &m_control_socket;
  else
    socket = &m_data_socket;

  ssize_t bytes_sent = socket->SendTo(
      reinterpret_cast<const uint8_t*>(&packet),
      size,
      is_control ? m_control_addr : m_data_addr,
      is_control ? CONTROL_PORT : DATA_PORT);

  if (bytes_sent != static_cast<ssize_t>(size)) {
    OLA_INFO << "Only sent " << bytes_sent << " of " << size;
    return false;
  }
  return true;
}
Ejemplo n.º 6
0
/**
 * Handle a KiNet poll packet
 */
void HandlePoll(const struct sockaddr_in &source,
                const kinet_packet &packet,
                unsigned int size) {
  ssize_t r = udp_socket.SendTo(peer0_0, sizeof(peer0_0), source);
  OLA_INFO << "sent " << r << " bytes";
}
Ejemplo n.º 7
0
/**
 * Check that we receive OSC messages correctly.
 */
void OSCNodeTest::testReceive() {
  DmxBuffer expected_data;

  // Register the test OSC Address with the OSCNode using the DMXHandler as the
  // callback.
  OLA_ASSERT_TRUE(m_osc_node->RegisterAddress(
      TEST_OSC_ADDRESS, NewCallback(this, &OSCNodeTest::DMXHandler)));

  // Attempt to register the same address with a different path, this should
  // return false
  OLA_ASSERT_FALSE(m_osc_node->RegisterAddress(
      TEST_OSC_ADDRESS,
      NewCallback(this, &OSCNodeTest::DMXHandler)));

  // Using our test UDP socket, send the OSC_BLOB_DATA to the default OSC
  // port. The OSCNode should receive the packet and call DMXHandler.
  IPV4SocketAddress dest_address(IPV4Address::Loopback(),
                                 m_osc_node->ListeningPort());

  // send a single float update
  m_udp_socket.SendTo(OSC_SINGLE_FLOAT_DATA, sizeof(OSC_SINGLE_FLOAT_DATA),
                      dest_address);
  m_ss.Run();
  OLA_ASSERT_EQ(512u, m_received_data.Size());
  expected_data.SetChannel(0, 127);
  OLA_ASSERT_EQ(expected_data, m_received_data);

  // now send a blob update
  m_udp_socket.SendTo(OSC_BLOB_DATA, sizeof(OSC_BLOB_DATA),
                      dest_address);
  // Run the SelectServer, this will return either when DMXHandler
  // completes, or the abort timeout triggers.
  m_ss.Run();

  OLA_ASSERT_EQ(11u, m_received_data.Size());
  expected_data.SetFromString("0,1,2,3,4,5,6,7,8,9,10");
  OLA_ASSERT_EQ(expected_data, m_received_data);

  // Now try sending a float update.
  m_udp_socket.SendTo(OSC_SINGLE_FLOAT_DATA, sizeof(OSC_SINGLE_FLOAT_DATA),
                      dest_address);
  m_ss.Run();
  OLA_ASSERT_EQ(11u, m_received_data.Size());
  expected_data.SetChannel(0, 127);
  OLA_ASSERT_EQ(expected_data, m_received_data);

  // Now try sending an int update.
  m_udp_socket.SendTo(OSC_SINGLE_INT_DATA, sizeof(OSC_SINGLE_INT_DATA),
                      dest_address);
  m_ss.Run();
  OLA_ASSERT_EQ(11u, m_received_data.Size());
  expected_data.SetChannel(5, 140);
  OLA_ASSERT_EQ(expected_data, m_received_data);

  // An 'ii' update
  m_udp_socket.SendTo(OSC_INT_TUPLE_DATA, sizeof(OSC_INT_TUPLE_DATA),
                      dest_address);
  m_ss.Run();
  OLA_ASSERT_EQ(11u, m_received_data.Size());
  expected_data.SetChannel(7, 90);
  OLA_ASSERT_EQ(expected_data, m_received_data);

  // An 'if' update
  m_udp_socket.SendTo(OSC_FLOAT_TUPLE_DATA, sizeof(OSC_FLOAT_TUPLE_DATA),
                      dest_address);
  m_ss.Run();
  OLA_ASSERT_EQ(11u, m_received_data.Size());
  expected_data.SetChannel(8, 127);
  OLA_ASSERT_EQ(expected_data, m_received_data);

  // De-regsiter
  OLA_ASSERT_TRUE(m_osc_node->RegisterAddress(TEST_OSC_ADDRESS, NULL));
  // De-register a second time
  OLA_ASSERT_TRUE(m_osc_node->RegisterAddress(TEST_OSC_ADDRESS, NULL));
}