Part Number: MSP432E401Y
Tool/software: Code Composer Studio
Hello,
I want my MSP432E401Y to work as a client and connect to the PC. In the example tcpecho, although a connection is established with the PC, the microcontroller waits (accept ()) for a request. I want the microcontroller to send the connection request (connect ()).
I did the following but unfortunately it does not work. what am I doing wrong?
regards,
Fares
/*
* ======== tcpHandler ========
* Creates new Task to handle new TCP connections.
*/
void tcpHandler(uint32_t arg0, uint32_t arg1)
{
void *thread = NULL;
int status;
int server;
struct sockaddr_in clientAddr;
int optval;
int optlen = sizeof(optval);
socklen_t addrlen = sizeof(clientAddr);
Display_printf(displayOut, 0, 0, "TCP Echo example started\n");
bzero(&server, addrlen);
clientAddr.sin_family = AF_INET;
clientAddr.sin_addr.s_addr = INADDR_ANY;
clientAddr.sin_port = htons(arg0);
server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (server == -1) {
Display_printf(displayOut, 0, 0, "tcpHandler: socket failed\n");
goto shutdown;
}
optval = 1;
setsockopt(server, SOL_SOCKET, SO_REUSEADDR, (char *) &optval,
optlen);
status =connect(server, (struct sockaddr *)&clientAddr, addrlen);
if (status == -1) {
Display_printf(displayOut, 0, 0, " network:tcp Error in connect\n");
goto shutdown;
}