Hello, I have problem with TLS server. I want to write my own simple TLS server with Secure socket I/O. Problem is, that I can connect to server, accept connection, send data to client, bud when I read data from client, first read is OK, but when I send second packet I gave this error: Renegotiation failed: session id context uninitialized I googled about this error and find, that "session id context uninitialized" error come from OpenSSL. As client I use is Mozilla Thunderbird. Apologize for my english and thanks for any help :-) Below is fragment of my code: // PJ Initialization status = pj_init(); // Must create a pool factory before we can allocate any memory pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); // Create application pool for misc pool = pj_pool_create(&cp.factory, "udpserver", 1000, 1000, NULL); // Create IO queue status = pj_ioqueue_create(pool, 4, &ioQueue); pj_ssl_sock_param_default(¶m); param.cb.on_accept_complete = &onAcceptComplete; param.cb.on_data_read = &onDataRead; param.proto = SSL_PROTO; param.require_client_cert = REQUIRE_CLIENT_CERT; param.server_name = pj_str("tlsserver"); param.ioqueue = ioQueue; param.read_buffer_size = BUFFER_LENGTH; param.send_buffer_size = BUFFER_LENGTH; param.sock_af = AF; param.user_data = this; // Init bind address with port status = pj_sockaddr_in_init(&addr, NULL, port); status = pj_ssl_sock_create(pool, ¶m, &serverSocket); status = pj_ssl_cert_load_from_files(pool, pj_strset2(&tmp1, (char*)CERT_CA_FILE), pj_strset2(&tmp2, (char*)CERT_FILE), pj_strset2(&tmp3, (char*)CERT_PRIVKEY_FILE), pj_strset2(&tmp4, (char*)CERT_PRIVKEY_PASS), &cert); status = pj_ssl_sock_set_certificate(serverSocket, pool, cert); // Init op key for send pj_ioqueue_op_key_init(&sendKey, sizeof(sendKey)); status = pj_ssl_sock_start_accept(serverSocket, pool, &addr, pj_sockaddr_get_len(&addr)); // Create listener thread and listen listen = true; status = pj_thread_create(pool, "threadListener", (pj_thread_proc*)&threadListener, this, PJ_THREAD_DEFAULT_STACK_SIZE, 0, &tListener); /* short send (in short connectionId, in string data); */ NS_IMETHODIMP TlsServer::Send(PRInt16 connectionId, const char *data, PRInt16 *_retval NS_OUTPARAM) { pj_status_t status; pj_ssize_t size; // Send data size = strlen(data); status = pj_ssl_sock_send(connections[connectionId], &sendKey, data, &size, 0); // Done *_retval = STATUS_OK; return NS_OK; } /* Thread listener body */ void* threadListener(TlsServer *tlsServer) { while (tlsServer->isListening()) { pj_time_val delay = {0, 10}; pj_ioqueue_poll(tlsServer->getIoQueue(), &delay); } return STATUS_OK; } pj_bool_t onAcceptComplete(pj_ssl_sock_t *ssock, pj_ssl_sock_t *newsock, const pj_sockaddr_t *src_addr, int src_addr_len) { tlsServer = (TlsServer*) pj_ssl_sock_get_user_data(ssock); // Start reading data status = pj_ssl_sock_start_read(newsock, tlsServer->getPool(), BUFFER_LENGTH, 0); if (status != PJ_SUCCESS) { return PJ_FALSE; } return PJ_TRUE; } /* Server receive message */ pj_bool_t onDataRead(pj_ssl_sock_t *ssock, void *data, pj_size_t size, pj_status_t status, pj_size_t *remainder) { if (status != PJ_SUCCESS) { PJ_LOG(3, ("TS:DataRead", "Error when receive datagram #%i", status)); return PJ_FALSE; } char receiveData[BUFFER_LENGTH]; strncpy(receiveData, (char*)data, size); receiveData[size] = '\0'; tlsServer->receiveMessage(connectionId, receiveData); return PJ_TRUE; }