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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:35:51+00:00 2026-06-05T15:35:51+00:00

I am having some trouble figuring out why I am only receiving one reply

  • 0

I am having some trouble figuring out why I am only receiving one reply from a server application running on my computer(LocalHost). I do not have the source for this server application but it is a java application. Messages that is sent is a xml structure and have to end with a EoT tag.

The communication:

  1. Client connect to sever.
  2. Client sends message to server.
  3. Server sends message recived to client.
  4. Client sends message to server.
  5. Server sends a End of Transmission character.
  6. Client sends message to server.
  7. Server sends a End of Transmission character.

This is how my client connect, send and receive:

public bool ConnectSocket(string server, int port)
{
System.Net.IPHostEntry hostEntry = null;

    try
    {
        // Get host related information.
        hostEntry = System.Net.Dns.GetHostEntry(server);
    }
    catch (System.Exception ex)
    {
            return false;
    }


    // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
    // an exception that occurs when the host IP Address is not compatible with the address family
    // (typical in the IPv6 case).
    foreach (System.Net.IPAddress address in hostEntry.AddressList)
    {
            System.Net.IPEndPoint ipe = new System.Net.IPEndPoint(address, port);
            System.Net.Sockets.Socket tempSocket = new System.Net.Sockets.Socket(ipe.AddressFamily, System.Net.Sockets.SocketType.Stream, 
                                                                                 System.Net.Sockets.ProtocolType.Tcp);
            tempSocket.Connect(ipe);

            if (tempSocket.Connected)
            {
                m_pSocket = tempSocket;
                m_pSocket.NoDelay = true;
                return true;
            }
            else
                continue;
        }
        return false;
    }
}

public void Send(string message)
{
    message += (char)4;//We add end of transmission character
    m_pSocket.Send(m_Encoding.GetBytes(message.ToCharArray()));
}

private void Recive()
{
    byte[] tByte = new byte[1024];
    m_pSocket.Receive(tByte);
    string recivemessage = (m_Encoding.GetString(tByte));
}
  • 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-05T15:35:53+00:00Added an answer on June 5, 2026 at 3:35 pm

    Your Receive code looks very wrong; you should never assume that packets arrive in the same constructions that the server sends messages – TCP is just a stream. So: you must catch the return from Receive, to see how many bytes you received. It could be part of one message, an entire message, multiple entire messages, or the last half of one message and the first half of the next. Normally, you need some kind of “framing” decision, which could mean “messages split by LF characters”, or could mean “the length of each message is prefixed by network-byte-order integer, 4 bytes”. This usually means you need to buffer until you have a full frame, and worry about spare data at the end of the buffer that is part of the next frame. Key bits to add, though:

    int bytes = m_pSocket.Receive(tByte);
    // now process "bytes" bytes **only** from tByte, nothing that this
    // could be part of a message, an entire message, several messages, or
    // the end of message "A", the entire of message "B", and the first byte of
    // message "C" (which might not be an entire character)
    

    In particular, with text formats, you cannot start decoding until you are sure you have an entire message buffered, because a multi-byte character might be split between two messages.

    There may well also be problems in your receive loop, but you don’t show that (nothing calls Receive), so we can’t comment.

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

Sidebar

Related Questions

I having some trouble figuring this problem out where I have one button which
I'm having some trouble figuring out hot to update a UILabel twice in one
I'm having some trouble figuring out why I can only get the children of
I'm having some trouble figuring out how to use more than one left outer
I'm having some trouble with figuring out a way of unsubscribing from some anonymous
I'm having some trouble figuring out how to add elements to a parent object
I'm having some trouble figuring out to call methods that I have in other
I'm having some trouble figuring out how to make a reference to a subroutine
I'm having some trouble figuring this out. I have an unordered list menu that
I having trouble figuring out the correct architecture for this kind of application: it's

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.