asdasdasdasd

Dependencies:   Audio EthernetInterface mbed-rtos mbed

Fork of FRDM_TCP_v4_copy by Tigaresi

main.cpp

Committer:
emilmont
Date:
2012-07-26
Revision:
2:563aa530f0dd
Parent:
1:a51d8ed156e6
Child:
3:3fbf0efec25a

File content as of revision 2:563aa530f0dd:

#include "mbed.h"
#include "EthernetInterface.h"

const char* ECHO_SERVER_ADDRESS = "10.2.131.73";
const int ECHO_PORT = 7;

int main() {
    EthernetInterface eth;
    eth.init(); //Use DHCP
    eth.connect();
    printf("IP Address is %s\n", eth.getIPAddress());
    
    TCPSocketConnection sock;
    while (sock.connect(ECHO_SERVER_ADDRESS, ECHO_PORT) < 0) {
        printf("Unable to connect to (%s) on port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_PORT);
        wait(1);
    }
    
    char hello[] = "Hello World\n";
    sock.send_all(hello, sizeof(hello) - 1);
    
    char buf[256];
    int n = sock.receive(buf, 256);
    buf[n] = '\0';
    printf("%s", buf);
    
    sock.close();
    eth.disconnect();
    
    while(true) {}
}