Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years ago.
TCPSocket client.close() causes hardware fault.
Yesterday I received the MBED OS 5.10.1 available newsletter, in that newsletter it is said that an issue regarding client.accept() returning a NULL pointer was solved in the current MBED OS release.
I had some problems a few weeks ago regarding this so naturally I had to try ... You'll find the code I've written below.
EthernetInterface iface;
//TCPServer server;
TCPSocket server;
TCPSocket *client;
SocketAddress clientAddress;
int main (void)
{
iface.connect();
pc.printf("\n\nServer IP Address is %s\n", iface.get_ip_address());
server.open(&iface);
server.bind(SERVER_PORT);
server.listen(10);
while (true) {
pc.printf("Server bound and listening\n");
// server.accept(&client, &clientAddress);
client = server.accept();
char buffer[1024];
int n = client->recvfrom(&clientAddress, buffer, sizeof(buffer));
pc.printf("Connection succeeded!\nClient local stack address: 0x%08X\nClient's IP address: %s:%d\n\n", client,
clientAddress.get_ip_address(), clientAddress.get_port());
pc.printf("Received %u bytes from remote host\n", n); //print received message to terminal
buffer[n] = NULL;
pc.printf("Received message from Client :'%s'\n", buffer);
pc.printf("Sending echo to client\n");
client->send(buffer, n);
client->close();
}
}
The software implements a simple TCPSocket echo server and produces the output below.
Server IP Address is 192.168.1.15 Server bound and listening Connection succeeded! Client local stack address: 0x100032C0 Client's IP address: 192.168.1.8:51486 Received 10 bytes from remote host Received message from Client :'Hallo MBED' Sending echo to client ++ MbedOS Fault Handler ++ FaultType: HardFault Context: R0 : 000063A1 R1 : 100029C8 R2 : 10001474 R3 : 00000001 R4 : 00000002 R5 : 000063A1 R6 : 00000000 R7 : 00000000 R8 : 100025A8 R9 : 0000C91E R10 : 00000000 R11 : 00000000 R12 : 10000B68 SP : 10007FB0 LR : 00012C73 PC : 0000FE78 xPSR : 21001C0B PSP : 10001470 MSP : 10007F90 CPUID: 412FC230 HFSR : 40000000 MMFSR: 00000000 BFSR : 00000004 UFSR : 00000000 DFSR : 0000000A AFSR : 00000000 Mode : Handler Priv : Privileged Stack: MSP -- MbedOS Fault Handler -- ++ MbedOS Error Info ++ Error Status: 0x80FF013D Code: 317 Module: 255 Error Message: Fault exception Location: 0xD859 Error Value: 0xFE78 Current Thread: Id: 0x100029C8 Entry: 0xDACB StackSize: 0x1000 StackMem: 0x100019C8 SP: 0x10007F48 For more info, visit: https://armmbed.github.io/mbedos-error/?error=0x80FF013D -- MbedOS Error Info --
My TCP client application received the echo ... so the line that generated the MBedOS Error must certainly be client->close(). Am I doing something wrong?
Kind regards,
Koen