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.
tcp.cpp
- Committer:
- jonivdh
- Date:
- 2020-03-26
- Revision:
- 1:fda3af7f9bf7
- Parent:
- 0:6c9daa430100
File content as of revision 1:fda3af7f9bf7:
#include "tcp.h"
TCP::TCP () {
ip = 101;
char buffer[128];
IPString = "";
net.set_network ("192.168.0.118", "255.255.255.0", "0");
net.connect();
}
void TCP::send(int ip) {
IPString = "192.168.0." + to_string(ip);
// Open a socket on the network interface, and create a TCP connection to mbed.org
socket.open(&net);
socket.connect(IPString.c_str(), 4000);
// Send a simple http request
char number [] = "hallo";
socket.send(number,sizeof number);
// Close the socket to return its memory and bring down the network interface
socket.close();
// Bring down the ethernet interface
net.disconnect();
printf("Done\n");
}
void TCP::receive() {
int rcount = 0;
EthernetInterface net;
TCPSocket server;
server.open(&net);
server.bind(4000);
server.listen();
TCPSocket * receiv = server.accept();
rcount = receiv->recv(buffer, sizeof buffer);
printf("recv %d [%.*s]\n", rcount, strstr(buffer, "\r\n")-buffer, buffer);
receiv->close();
}