I have a card PIC32 Ethernet Starter Kit II (PIC32MX795F512L) I use and MPLAB X IDE v4.20 with MPLAB Harmony v2_06.
I would like to create a client/server code to send/receive frames (bytes) between a Raspberry PI and my ESK II card. the Raspberry PI, the ESK II and my computer are connected on the same network with RJ45 cables using a switch.
To do this, I was advised to use MPLAB Harmony demo berkeley_tcp_server .
I created a client program with python on the RPI and I executed the berkeley_tcp_server project for ESK II, my python code allows to send 'Hello' to the same port as the ESK II, the berkeley_tcp_server program allows it to take what is received in the buffer and returned to the port .... so on the shell of python I get 'Hello'
I would like to send a data frame (bytes) for example ([0x7E, 0x18, 0x01, ...]) from the ESK II to the RPI.

Here is the server code of the demo:
- Code: Select all
// Create a socket for this server to listen and accept connections on
SOCKET tcpSkt = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (tcpSkt == INVALID_SOCKET)
return;
appData.bsdServerSocket = (SOCKET) tcpSkt;
appData.state = APP_BSD_BIND;
}
break;
case APP_BSD_BIND:
{
// Bind socket to a local port
struct sockaddr_in addr;
int addrlen = sizeof (struct sockaddr_in);
addr.sin_port = SERVER_PORT;
addr.sin_addr.S_un.S_addr = IP_ADDR_ANY;
if (bind(appData.bsdServerSocket, (struct sockaddr*) &addr, addrlen) == SOCKET_ERROR)
return;
appData.state = APP_BSD_LISTEN;
// No break needed
}
break;
case APP_BSD_LISTEN:
{
if (listen(appData.bsdServerSocket, MAX_CLIENT) == 0) {
appData.state = APP_BSD_OPERATION;
SYS_CONSOLE_PRINT("Waiting for Client Connection on port: %d\r\n", SERVER_PORT);
}
}
break;
case APP_BSD_OPERATION:
{
int length;
struct sockaddr_in addRemote;
int addrlen = sizeof (struct sockaddr_in);
char buffer[15];
for (i = 0; i < MAX_CLIENT; i++) {
// Accept any pending connection requests, assuming we have a place to store the socket descriptor
if (appData.ClientSock[i] == INVALID_SOCKET)
appData.ClientSock[i] = accept(appData.bsdServerSocket, (struct sockaddr*) &addRemote, &addrlen);
// If this socket is not connected then no need to process anything
if (appData.ClientSock[i] == INVALID_SOCKET)
continue;
// For all connected sockets, receive and send back the data
length = recv(appData.ClientSock[i], buffer, sizeof (buffer), 0);
if (length > 0) {
buffer[length] = '\0';
send(appData.ClientSock[i], buffer, strlen(buffer), 0);
}
// else just wait for some more data
}
}
break;
default:
break;
}
}
Thank you all