Hi,
I have been trying for a couple of weeks to create an mbed client that sends data over a TCP connection to a server. I have finally been able to get this working but I believe this has identified a bug as the behaviour is not as I expected.
My goal was to connect the client to a server and send data from the client only.
To re-create the unexpected behaviour, you need the code from this post for the mbed client and a working TCP server on which you can turn ECHO on and off.
Scenarios:
MBED (CHECK_RESPONSE = false) : SERVER (ECHO = ON or OFF): The mbed will send about 5 messages and then hang.
MBED (CHECK_RESPONSE = true) : SERVER (ECHO = OFF): The mbed will complete the loop, but only actually send about 20 messages.
MBED (CHECK_RESPONSE = true) : SERVER (ECHO = ON): This is completely successful, the mbed sends all data and the server receives all data.
I expected to be able to send data from the client for the server to process without any need for the server to send any data back. I am sorry, but identifying the bug itself is way above my level, but I do believe that there is a problem somewhere with the libraries.
Regards,
Arthur
#include "mbed.h"
#include "EthernetInterface.h"
const char* SERVER_ADDRESS = "192.168.1.200";
const int SERVER_PORT = 55555;
const bool CHECK_RESPONSE = true;
int main()
{
EthernetInterface eth; // declare interface
eth.init(); // initialize interface to use DHCP
eth.connect(); // connect interface
printf("\nIP Address aquired: %s\n", eth.getIPAddress()); // display IP address
TCPSocketConnection client; // set up a client socket
client.set_blocking(false,10); // limit client to a 10ms wait for response
if(!client.connect(SERVER_ADDRESS, SERVER_PORT)) // connect to server
{
printf ("Connected to Server\n");
char message[] = "Hello";
char response[256];
int bytes_sent;
int bytes_received;
int loop;
for (loop=0;loop<100;loop++)
{
// send data
bytes_sent = client.send_all(message, strlen(message));
printf("Sent: %d '%s' (Bytes: %d)\n",loop,message,bytes_sent);
// check for received data
if(CHECK_RESPONSE)
{
bytes_received = client.receive(response, 256);
if (bytes_received!=-1)
{
response[bytes_received] = '\0';
printf("Received: '%s' (Bytes: %d)\n",response, bytes_received);
}
}
}
}
else
{
printf("Unable to connect to server\n");
}
printf("Finished\n");
}
Hi,
I have been trying for a couple of weeks to create an mbed client that sends data over a TCP connection to a server. I have finally been able to get this working but I believe this has identified a bug as the behaviour is not as I expected.
My goal was to connect the client to a server and send data from the client only.
To re-create the unexpected behaviour, you need the code from this post for the mbed client and a working TCP server on which you can turn ECHO on and off.
Scenarios:
MBED (CHECK_RESPONSE = false) : SERVER (ECHO = ON or OFF): The mbed will send about 5 messages and then hang.
MBED (CHECK_RESPONSE = true) : SERVER (ECHO = OFF): The mbed will complete the loop, but only actually send about 20 messages.
MBED (CHECK_RESPONSE = true) : SERVER (ECHO = ON): This is completely successful, the mbed sends all data and the server receives all data.
I expected to be able to send data from the client for the server to process without any need for the server to send any data back. I am sorry, but identifying the bug itself is way above my level, but I do believe that there is a problem somewhere with the libraries.
Regards,
Arthur