Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NetworkSocketAPI WizFi310Interface mbed
Fork of WizFi310_TCP_Echo_Server_Example by
main.cpp
- Committer:
- stkim92
- Date:
- 2017-04-18
- Revision:
- 1:5981ba4a8323
- Parent:
- 0:50932ef4b276
- Child:
- 2:8d119e9b8f5a
File content as of revision 1:5981ba4a8323:
/* NetworkSocketAPI Example Program * Copyright (c) 2015 ARM Limited * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "mbed.h" #include "TCPSocket.h" #include "mbed.h" #include "WizFi310Interface.h" #include "TCPSocket.h" #include "TCPServer.h" #define TARGET_NUCLEO_F411RE #if defined(TARGET_NUCLEO_F411RE) //Serial pc(USBTX, USBRX); //WizFi310Internet wifi(PA_11, PA_12, D6, D7, D3, NC, 115200); //WizFi310Interface wifi(D8, D2, D7, D6, D9, NC, 115200); #endif #if defined(TARGET_WIZwiki_W7500) Serial pc(USBTX, USBRX); WizFi310Interface wifi(D1, D0, D7, D6, D8, NC, 115200); #endif #define AP_SSID "wizms1" #define AP_PASSWORD "maker0701" #define AP_SECURITY NSAPI_SECURITY_WPA2 int main() { pc.baud(115200); printf("WizFi310 NetworkSocketAPI TCP Server Example\r\n"); wifi.connect(AP_SSID, AP_PASSWORD, AP_SECURITY); const char *ip = wifi.get_ip_address(); const char *mac = wifi.get_mac_address(); printf("IP address is: %s\r\n", ip ? ip : "No IP"); printf("MAC address is: %s\r\n", mac ? mac : "No MAC"); TCPServer srv; TCPSocket clt_sock; SocketAddress clt_addr; srv.open(&wifi); srv.set_blocking(true); srv.bind(80); srv.listen(); srv.accept(&clt_sock); char buffer[512]; while (true) { int n = clt_sock.recv(buffer, sizeof(buffer)); if( n < 0 ) { clt_sock.close(); srv.close(); } if( n > 0 ) { buffer[n] = '\0'; printf("length : %d\r\n", n); clt_sock.send(buffer, n); } } }