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 7758855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:28:30+00:00 2026-06-01T13:28:30+00:00

I make a java socket server and c socket client, here are the code

  • 0

I make a java socket server and c socket client, here are the code

Java Socket Server:

int Send_Request(String s) {

    try {
        os = socket.getOutputStream();
        os.write(s.getBytes());
        os.flush();

        Log.d(tag,"Data = " + s);

        return 0;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        Log.e(tag,"Send Request Error");
        return -1;
    }

C socket client:

void* recv_request()
{
int i,in;
char buf[1024];
while(1)
{
    if ( ( in = read(sockfd, buf, strlen(buf)) ) != -1 )
    {
        LOGD("Received = %s ...",buf);
        sendServerCutText(buf);
        memset(buf,0,strlen(buf));
    }

}

}

The problem is .. when i send from the server, it is blocking on flush(), the c client cannot receive until there is another Send_Request called.

where is the problem??

  • 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-06-01T13:28:32+00:00Added an answer on June 1, 2026 at 1:28 pm

    There is a conceptual problem. You think TCP is message oriented (sending messages with specified length). It’s not like that, it is only providing a stream of bytes.

    For sending a message with a specified length a common technique is to send first the length (encoded in fixed length, eg 4 byte integer in network byte order) and then the actual message.

    There’s also an implementation problem, the 3rd argument for read should be the maximum read length, which should be 1024, executing strlen on a non-initialized local char array is clearly undefined-behaviour.

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

Sidebar

Related Questions

I'm trying to make a client/server Java App. Both client and server will be
I write client-server appliaction. Client is on android, server on plain Java. I want
I'm trying to make a simple http client server using java. It will show
Is it possible to make a Java program that prints its source code to
I'm trying to make a Java program more Groovy. The java code reads an
I am trying to make a simple Client-Server application but when I execute the
I have a project to develop a client server application in java . This
Got a problem about server-client: When server is running, if I want to make
I have the following web server class found here . I need to write
I've always wanted a way to make a socket connection to a server and

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.