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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:55:28+00:00 2026-05-24T02:55:28+00:00

I wanna send data from client to server. There are two queues. in client

  • 0

I wanna send data from client to server. There are two queues. in client side and in server side. I want to my client to be connected to the server and send all the data in client queue to the server. In server side I wanna accept all the clients and get all objects and add to the server side queue

Client code :

Queue<Person> clientQueue;   // This is the client side queue

IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 15884);
var client = new TcpClient();

while(!clientQueue.IsEmpty)
{
    Person personObj = clientQueue.Dequeue();

    client.Connect(serverEndPoint);
    NetworkStream clientStream = client.GetStream();
    BinaryFormatter bf = new BinaryFormatter();
    bf.Serialize(clientStream, personObj);
    clientStream.Flush();
}

Server Side :

Queue<Person> serverQueue;   // This is the server side queue

IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 15884);
TcpListener tcpListener = new TcpListener(ipEndPoint);


while(true)
{
    TcpClient client = tcpListener.AcceptTcpClient();
    NetworkStream clientStream = tcpClient.GetStream();
    BinaryFormatter bf = new BinaryFormatter();
    Person person = (Person)bf.Deserialize(clientStream);
    tcpClient.Close();

    serverQueue.Enqueue(person);
}

I know above code is not working. I just wanna sketch my design. Can someone please send me the code example. How to send client queue to server queue..

Thanks..

  • 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-24T02:55:29+00:00Added an answer on May 24, 2026 at 2:55 am

    Ok. Finally I found the answer for my question doing some investigations/Testings. I ll post it here for someone else.. 🙂

    In my client side first I have to send how much bytes im gonna send to server. and then send that data.. Like this..

    Queue<Person> clientQueue;   // This is the client side queue
    
    IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 15884);
    var client = new TcpClient();
    
    NetworkStream clientStream = client.GetStream()
    
    while (disconnectClient)
    {
        if (clientQueue.Count > 0)
        {
             Person person = clientQueue.Dequeue();
             using (MemoryStream memoryStrem = new MemoryStream())
             {
                  var bf = new BinaryFormatter();
                  bf.Serialize(memoryStrem, person);
    
                  byte[] writeData = memoryStrem.ToArray();
    
    
                  byte[] writeDataLen = BitConverter.GetBytes((Int32)writeData.Length);
                  clientStream.Write(writeDataLen, 0, 4);
                  clientStream.Write(writeData, 0, writeData.Length);
             }
        }
    }
    clientStream.Dispose();
    client.Dispose();
    

    In Server Side :

    Queue<Person> serverQueue;   // This is the server side queue
    
    IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 15884);
    TcpListener tcpListener = new TcpListener(ipEndPoint);
    tcpListener.Start();
    
    while(true)
    {
        TcpClient tcpClient = tcpListener.AcceptTcpClient();
        NetworkStream clientStream = tcpClient.GetStream();
    
        while (client.Connected)
        {
            if (client.Available >= 4)
            {
                try
                {
                     byte[] readDataLen = new byte[4];
                     clientStream.Read(readDataLen, 0, 4);
    
                     Int32 dataLen = BitConverter.ToInt32(readDataLen, 0);
                     byte[] readData = new byte[dataLen];
    
                     clientStream.Read(readData, 0, dataLen);
    
                     using (var memoryStream = new MemoryStream())
                     {
                          memoryStream.Write(readData, 0, readData.Length);
                          memoryStream.Position = 0;    /// This is very important. It took 4 hrs to identify an error because of this :)
    
                          BinaryFormatter bf = new BinaryFormatter();
                          Person person = (Person)bf.Deserialize(memoryStream);
    
                          serverQueue.Enqueue(person);
                     }
                }
                catch { }
            }
        }
        tcpClient.Close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In .NET CF 3.5 (on Windows CE 5.0), i wanna send receive data to/from
I wanna place two child un-ordered lists side by side. They are having Class
I am developing a Facebook Application an i wanna send a video file from
I wanna create queue management system (for bank, hostpital...) Something like that There will
I wanna to use post function of jQuery to send data to php code,the
I am sending SMS by AT commands with GSM mobile phone. I wanna send
I wonna send email through gmail smtp, but users should see my corporative From
I wanna get the Timedate value from another page using request.querystring and then use
I wanna add server controls by using javascript. The main purpose of why I
i have this event handler Temp.MouseLeftButtonDown += new MouseButtonEventHandler(Temp_MouseLeftButtonDown); but i wanna send some

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.