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

  • Home
  • SEARCH
  • 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 8577441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:09:38+00:00 2026-06-11T20:09:38+00:00

I am developing a windows based chat application. When the client first sends the

  • 0

I am developing a windows based chat application. When the client first sends the Command class, server gets it processes it and acknowledges the client by sending another Command class.

(I have numbered the code segment to spot the flow of the program)

Everything goes well until the sever send back the acknowledgment. When the code runs in client (5.) to deserialize and get the copy of the acknowledgment, the client program goes unresponsive. But the code in the server (6.) seems working – it serializes the command succesfully.

Can anyone point out whats wrong here?

Thanks in advance.

Server Code:

//1. Server runs first
try
{
    BinaryFormatter binaryFormatter = new BinaryFormatter();

    //2. Server is blocked here waiting for an incoming stream
    Command newCommand = (Command)binaryFormatter.Deserialize(networkStream);
}
catch (Exception ex)
{
    MessageBox.Show("EXCEPTION: " + ex.Message);
    Console.WriteLine(ex.Message);
}

Client c = new Client(newCommand.ClientName, endPoint,
                                        clientServiceThread, client);

// ...processing the newCommand object

Command command = new Command(CommandType.LIST);

try
{
    TcpClient newTcpClient = new TcpClient(newClient.Sock.RemoteEndPoint
                                                           as IPEndPoint);
    newTcpClient.Connect(newClient.Sock.RemoteEndPoint as IPEndPoint);
    NetworkStream newNetworkStream = newTcpClient.GetStream();
    BinaryFormatter binaryFormatter = new BinaryFormatter();

    //6. Server serializes an instance of the Command class to be recieved by the client
    binaryFormatter.Serialize(newNetworkStream, command);
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message, "Error");
    Console.WriteLine(ex.Message);
    newClient.Sock.Close();
    newClient.CLThread.Abort();
}

Client Code:

//3. Client runs second
TcpClient tcpClient = new TcpClient('localhost', 7777);
NetworkStream networkStream = tcpClient.GetStream();

Command newCommand = new Command(CommandType.CONN);

try
{
    BinaryFormatter binaryFormatter = new BinaryFormatter();

    //4. Client serializes an instance of a Command class to the NetworkStream
    binaryFormatter.Serialize(networkStream, newCommand);
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}


BinaryFormatter binaryFormatter = new BinaryFormatter();

//5. Then client is blocked until recieve an instance of command class to deserialize
Command serverResponse = (Command)binaryFormatter.Deserialize(networkStream);

clientForm.updateChatMessages(serverResponse);

//7. Instead of recieving the instance of the Command class, the clients go unresponsive
//   and the client program hangs.
  • 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-11T20:09:39+00:00Added an answer on June 11, 2026 at 8:09 pm

    I figured it out. Since the server was servicing multiple clients, I made a mistake of deserializing from the same NetworkStream instance. So I changed the code to create a new NetworkStream by providing the client’s socket each time I want the server to send a message.

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

Sidebar

Related Questions

I am developing a windows desktop client/server application in .NET where the client application
I am developing a windows based application in .net. I have two forms. Form2
Which use of connection management is better while developing a windows based application which
I have a tab-based application for windows, which I am developing by myself. I
I am developing a multiplatform (Windows, Linux and Mac) Qt based Phonon C++ application
suppose if i want to develop a windows chat application then a chat server
I am developing C# windows based application. I am getting System.ComponentModel.Win32Exception: Access is denied
We are developing C#.Net 4.0 Windows form based application using Microsoft.Office.Interop.Word reference. Now I
We are developing C# .net 4.0 Windows Form Based Application. Here, User Will enter
I'm developing a compact framework 3.5 application on a windows CE based scanner device.

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.