version_2.0
Dependents: cc3000_ping_demo_try_2
Fork of cc3000_hostdriver_mbedsocket by
Diff: cc3000.cpp
- Revision:
- 32:e62d7252401e
- Parent:
- 26:456f73ed2a75
- Child:
- 36:1f70a62a160e
- Child:
- 38:1d374a7f0c0d
--- a/cc3000.cpp Sun Oct 06 18:01:19 2013 +0200 +++ b/cc3000.cpp Sun Oct 06 18:25:12 2013 +0200 @@ -282,89 +282,6 @@ } #endif -cc3000_client cc3000::create_tcp_client(uint32_t ip_address, uint16_t port) { - sockaddr socket_address = {0}; - int32_t tcp_socket; - - tcp_socket = _socket.socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (tcp_socket == -1) { - DBG_CC("Failed to create new socket (tcp)"); - return cc3000_client(*this); - } - - socket_address.family = AF_INET; - socket_address.data[0] = (port & 0xFF00) >> 8; - socket_address.data[1] = (port & 0x00FF); - socket_address.data[2] = ip_address >> 24; - socket_address.data[3] = ip_address >> 16; - socket_address.data[4] = ip_address >> 8; - socket_address.data[5] = ip_address; - - if (_socket.connect(tcp_socket, &socket_address, sizeof(socket_address)) == -1) { - DBG_CC("Failed to connect (tcp)"); - _socket.closesocket(tcp_socket); - return cc3000_client(*this); - } - - return cc3000_client(*this, tcp_socket); -} -cc3000_client cc3000::create_udp_client(uint32_t ip_address, uint16_t port) { - sockaddr socket_address = {0}; - int32_t udp_socket; - - udp_socket = _socket.socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (udp_socket == -1) { - DBG_CC("Failed to create new socket (udp)"); - return cc3000_client(*this); - } - - socket_address.family = AF_INET; - socket_address.data[0] = (port & 0xFF00) >> 8; - socket_address.data[1] = (port & 0x00FF); - socket_address.data[2] = ip_address >> 24; - socket_address.data[3] = ip_address >> 16; - socket_address.data[4] = ip_address >> 8; - socket_address.data[5] = ip_address; - - if (_socket.connect(udp_socket, &socket_address, sizeof(socket_address)) == -1) { - DBG_CC("Failed to connect (udp)"); - _socket.closesocket(udp_socket); - return cc3000_client(*this); - } - - return cc3000_client(*this, udp_socket); -} - -cc3000_server cc3000::create_tcp_server(uint32_t ip_address, uint16_t port) { - sockaddr socket_address = {0}; - int32_t tcp_socket; - - tcp_socket = _socket.socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (tcp_socket == -1) { - DBG_CC("Failed to create new socket."); - return cc3000_server(*this, socket_address); - } - - socket_address.family = AF_INET; - socket_address.data[0] = (port & 0xFF00) >> 8; - socket_address.data[1] = (port & 0x00FF); - socket_address.data[2] = ip_address >> 24; - socket_address.data[3] = ip_address >> 16; - socket_address.data[4] = ip_address >> 8; - socket_address.data[5] = ip_address; - - if (_socket.bind(tcp_socket, &socket_address, sizeof(socket_address)) != 0) { - DBG_CC("Failed to bind the new socket"); - return cc3000_server(*this, socket_address); - } - if (_socket.listen(tcp_socket, 1) != 0) { /* 1 client */ - DBG_CC("Failed to listen on the new socket"); - return cc3000_server(*this, socket_address); - } - - return cc3000_server(*this, socket_address, tcp_socket); -} - void cc3000::delete_profiles(void) { tUserFS user_info;