net_socket *net_protocol::connect_to_server(char const *&server_name, int port, int force_port, net_socket::socket_type sock_type) { net_address *a = get_node_address(server_name, port, force_port); if (!a) return NULL; net_socket *s = connect_to_server(a, sock_type); delete a; return s; }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(udp_client_process, ev, data) { static struct etimer periodic; static struct ctimer backoff_timer; PROCESS_BEGIN(); PRINTF("Configuring sensors... "); leds_on(LEDS_GREEN); i2c_init(); leds_on(LEDS_YELLOW); if(i2c_start(ADG715_A|I2C_WRITE)){ leds_on(LEDS_RED); } i2c_write(0xFF); leds_off(LEDS_YELLOW); PRINTF("done!\n"); PROCESS_PAUSE(); set_global_address(); PRINTF("UDP client process started\n"); print_local_addresses(); /* new connection with remote host */ /* TEST PARA RAFA */ uip_ipaddr_t ipaddr; get_node_address(&ipaddr); ipaddr.u16[7] = 0xFFFF; PRINT6ADDR(&ipaddr); client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); PRINTF("Created a connection with the server "); PRINT6ADDR(&client_conn->ripaddr); PRINTF(" local/remote port %u/%u\n", UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport)); etimer_set(&periodic, SEND_INTERVAL); while(1) { PROCESS_YIELD(); if(ev == tcpip_event) { tcpip_handler(); } if(etimer_expired(&periodic)) { etimer_reset(&periodic); ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL); } } PROCESS_END(); }