cancel
Showing results for 
Search instead for 
Did you mean: 

regarding to server tls part

salma-banu
Associate

hii,

 

 

static WOM_Status_t App_Server_Thread_Entry(ULONG thread_input)
{
printf("\r\n***********server started task ***********\r\n");
 
ULONG SourceIpAddress;
NX_PACKET *DataPacket;
ULONG bytes;
UINT SourcePort;
ULONG BytesRead;
 
/* create the TCP socket */
ret = nx_tcp_socket_create(&NetXDuoEthIpInstance, &TCPSocket, "TCP Server Socket", NX_IP_NORMAL, NX_FRAGMENT_OKAY,
NX_IP_TIME_TO_LIVE, WINDOW_SIZE, NX_NULL, NX_NULL);
 
/* Create a TLS session for our socket. This sets up the TLS session object for later use */
ret = nx_secure_tls_session_create(&server_tls_session, &nx_crypto_tls_ciphers_ecc, server_tls_crypto_metadata, sizeof(server_tls_crypto_metadata));
 
/* Initialize ECC parameters for this session. */
ret = nx_secure_tls_ecc_initialize(&server_tls_session, nx_crypto_ecc_supported_groups, nx_crypto_ecc_supported_groups_size, nx_crypto_ecc_curves);
 
/* Set the packet reassembly buffer for this TLS session. */
ret = nx_secure_tls_session_packet_buffer_set(&server_tls_session, server_tls_packet_buffer, sizeof(server_tls_packet_buffer));
 
/* Initialize the nx_secure certificate */
ret = nx_secure_x509_certificate_initialize(&server_certificate, (UCHAR *)certificate_data, certificate_length, NX_NULL, 0, private_key, private_key_length, NX_SECURE_X509_KEY_TYPE_RSA_PKCS1_DER);
 
/* Add identity certificate. */
ret = nx_secure_tls_local_certificate_add(&server_tls_session, &server_certificate);
 
/* listen to new client connections.*/
ret = nx_tcp_server_socket_listen(&NetXDuoEthIpInstance, SERVER_PORT, &TCPSocket, MAX_TCP_CLIENTS, tcp_listen_callback);
printf("COMMs server Listening PORT : %d \n", SERVER_PORT);
 
/*checking the status of a semaphore acquisition attempt using the tx_semaphore_get function*/
if (tx_semaphore_get(&Semaphore, TX_WAIT_FOREVER) != TX_SUCCESS)
{
Error_Handler();
}
else
{
 
while (1)/*Infinite loop for handling incoming TCP connections and processing data.*/
{
/*accept the tcp server socket*/
ret = nx_tcp_server_socket_accept(&TCPSocket, NX_WAIT_FOREVER);
 
/*Conditional check for a successful operation soft_ver*/
 
if (ret == NX_SUCCESS)
{
ret = nx_secure_tls_session_start(&server_tls_session, &TCPSocket, NX_WAIT_FOREVER);
while (1)//Loop for receiving and processing TLS data or handling server disconnection and re-listening.
{
ret = nx_secure_tls_session_receive(&server_tls_session, &DataPacket, NX_WAIT_FOREVER);
 
if (ret == NX_SUCCESS)/*check the ret status if its equal to NX_SUCCESS do the following operation*/
{
TX_MEMSET(data_buffer, '\0', sizeof(data_buffer));
 
ret = nx_packet_data_extract_offset(DataPacket, 0, data_buffer, 100, &bytes);
 
nx_udp_source_extract(DataPacket, &SourceIpAddress, &SourcePort);
 
nx_packet_data_retrieve(DataPacket, data_buffer, &BytesRead);
 
PRINT_DATA(SourceIpAddress, SourcePort, data_buffer);
 
WOM_receive_parse_data(data_buffer);
 
nx_packet_release(DataPacket);
}
else
{
printf("server disconnected, waiting for new connection\n");
nx_tcp_socket_disconnect(&TCPSocket, NX_WAIT_FOREVER);
nx_tcp_server_socket_unaccept(&TCPSocket);
nx_tcp_server_socket_relisten(&NetXDuoEthIpInstance, SERVER_PORT, &TCPSocket);
break;
}
}
}
else
{
printf("Error in accepting client connection: %d\n", ret);
}
}
}
return WOM_SUCCESS;
}
 
this is my TLS server part code, it is working fine, but when ethernet cable is disconnected, and reconnected, this server part is getting failed to communicate with host please help me to come-out from this issue. 

 

 

0 REPLIES 0