Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7591245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:36:15+00:00 2026-05-30T20:36:15+00:00

I have a client/server program and applet. I will show the code below. Can

  • 0

I have a client/server program and applet. I will show the code below. Can you please tell me why and where the programs are blocking if at all. The applet seems to stick but when I close the Cpp side it finishes executing. Heres the code (I left out the imports and includes).

public class first extends JApplet  {

    PrintWriter toServer = null;
    BufferedReader fromServer = null;

    public void init() {

        System.setProperty("javax.net.ssl.keyStore", "javakeys");
        System.setProperty("javax.net.ssl.keyStorePassword", "javakeys");

try {

        SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
        SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket("localhost", 4000);

        toServer = new PrintWriter(sslsocket.getOutputStream(), true);

        InputStreamReader isr = new InputStreamReader(sslsocket.getInputStream());
        fromServer = new BufferedReader(isr);

    } catch (Exception exception) {
            exception.printStackTrace();
    }

        toServer.println("Flystar".getBytes()); 

    }

    public void paint(Graphics g) {

        g.setColor( Color.red );
        g.drawString("Welcome to Java!!", 50, 60 );
    }


}

And here’s the Cpp…

int conn_new_server( int );

__attribute__((constructor)) void construct_ssl()
{
    SSL_load_error_strings();
    SSL_library_init();
    OpenSSL_add_all_algorithms();
}

__attribute__((destructor)) void destruct_ssl()
{
    ERR_free_strings();
    EVP_cleanup();
}

int main()
{
    int sockfd, client;
    SSL_CTX *tlsctx;
    SSL *ssl;
    char recvit[256];

    printf("Status %d\n", RAND_status());
    tlsctx = SSL_CTX_new( TLSv1_server_method());
    SSL_CTX_set_options(tlsctx, SSL_OP_SINGLE_DH_USE);
    SSL_CTX_use_certificate_file(tlsctx, "server.crt" , SSL_FILETYPE_PEM);
    SSL_CTX_use_PrivateKey_file(tlsctx, "server.key", SSL_FILETYPE_PEM);

    sockfd = conn_new_server( 1337 );
    while (1)
    {
        client = accept(sockfd, NULL, NULL);
        ssl = SSL_new(tlsctx);
        SSL_set_fd(ssl, client);
        SSL_accept(ssl);

        cout << "connection detected!\n\r";

        while(1)    {

//            SSL_write( ssl, "hello", sizeof("hello"));
          SSL_read( ssl, recvit, sizeof(recvit));
            cout << recvit << "\n\r";
        }

//      SSL_write(ssl, "Hi :3\n\r", 6);

        SSL_shutdown(ssl);
        SSL_free(ssl);
//       close(client);
    }
    SSL_CTX_free(tlsctx);
 //   close(sockfd);

    return 0;
}


int conn_new_server( int port)
{
    WSADATA g_wsadata;      // Winsock data holder
    int err;
    StartSocketLib;
    char *messageman = "Hello.\r\n";
    int recv_stat;
    int connsock = 0;
    char *testsendbuf = "This is very good!\r\n";
    list<int> socklist;

    // BEGIN CODE BLOCK 2.3 - Create a Listening Socket on port 4000
    int sock = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );

    if( sock == -1 ) {
        cout << "Socket creation error!" << endl;
        return 0;
    }

    cout << "Socket created!  Standing By." << endl;

// create a sockaddr_in for binding, listening on port 4000
    struct sockaddr_in socketaddress;
    socklen_t sa_size = sizeof( struct sockaddr_in );
    socketaddress.sin_family = AF_INET;
    socketaddress.sin_port = htons( 4000 );
    socketaddress.sin_addr.s_addr = htonl( INADDR_ANY );
    memset( &(socketaddress.sin_zero), 0, 8 );

    // bind the socket
    err = bind( sock, (struct sockaddr*)&socketaddress, sa_size );

    // listen on the socket
    err = listen( sock, 16 );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:36:16+00:00Added an answer on May 30, 2026 at 8:36 pm

    The number one issue here is using BufferedReader. It will try to fill up an internal buffer before returning any data to you, and if there’s not enough data to fill the buffer, it will block. If you’re using BufferedReader just to get the readLine() method — which is what you’re doing here — then when you construct it, pass a second constructor argument of 1, to set a buffer size of one character, essentially turning off buffering. That will most likely fix your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

all. I'm having a bit of weird problem with client server program. I have
I have a Client-Server program in C#. Here is the Server's code: ... String
I have a client/server program in c. While the server runs, I can send
I have a client/server program in TCP written in C, and I would like
I have a client and server program (both in Obj-C) and I am transferring
I have a classic client/server (fat client and database) program written in Delphi 2006.
I have client and server programs which now communicate via TCP. I'm trying out
I am developing an application in C# WPF which will have Client-Server architecture (Client
I have a client/server program that attempts to send and receive an object. There
In sockets I have written the client server program. First I tried to send

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.