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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:31:01+00:00 2026-06-02T22:31:01+00:00

I am trying to send simple string message from my desktop app using sockets

  • 0

I am trying to send simple string message from my desktop app using sockets here is the server side code which sends data to the client:

    swSenderSender = new StreamWriter(tcpClients[i].GetStream());
    swSenderSender.WriteLine(From + " says: " + Message);
    swSenderSender.Flush();
    swSenderSender = null;

I have Metro application – Client side code using DataReader:

    var dr = new DataReader(socket.InputStream);
    var stringHeader = await dr.LoadAsync(4);
    int strLength = dr.ReadInt32();
    uint numStrBytes = await dr.LoadAsync((uint)strLength);
    string msg = dr.ReadString(numStrBytes);

Here is the problem. DataReader needs to know how long is the string which were send. On the other side the StreamWriter cant sand nothing different than a simple string /or string with new lane. How to connect these two codes? Or maybe there is annother way to do this. Please help. I don’t know how to format the data to be able to send it between the client and the server.

  • 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-02T22:31:02+00:00Added an answer on June 2, 2026 at 10:31 pm

    The normal way this problem is solved in protocols is to put the length of the message first, in a fixed-length field, say length N. If you are never going to receive more than 999 characters in a message then N=3, for example. So your receive code devolves to

    receive N characters (or bytes, whatever).
    decode N to get number of characters following, say M.
    receive M characters.
    repeat ad nauseam.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the sample code from nodejs.org and trying to send the response
i'm trying to write simple tcp\ip client-server. here is server code: internal class Program
I'm trying to send messages generated by Google Protocol Buffer code via a simple
I am trying to do a simple app that will send email. The constructor
I'm trying to create a client-server program that send and receive a string (its
I am trying to send a simple email through the following code: protected void
I am trying to implement a simple chat program in linux using bsd sockets.
I am trying to Create a simple Tcp Server in C++ using Boost ASio
I am trying to send sms from java application using SMPPSim as SMS gateway
I'm trying to learn how to make a simple call to the server from

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.