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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:54:33+00:00 2026-05-27T01:54:33+00:00

I am using network stream to send a file name (example :text.txt) and then

  • 0

I am using network stream to send a file name (example :”text.txt”) and then send the file. the server is supposed to read the name and create a write stream to write the data in. the problem that the server gets the name + data from the file in the read command to get the name only. i think this is unclear.
the question i get the file name + some data from the file.
code that sends file name then file data:

ASCIIEncoding asci = new ASCIIEncoding();
TcpClient clientSocket = new TcpClient(textBox2.Text, 8880);
NetworkStream networkStream = clientSocket.GetStream();
byte[] b = asci.GetBytes(s);//s is the name of the file
networkStream.Write(b, 0, b.Length);
networkStream.Flush();

while(true)
{
    file = fileStream.Read(fileBuffer,0,fileBuffer.Length);
    networkStream.Write(fileBuffer,0,file);
    if(file == 0) break;
}

the code that the server rec. the name and data with

byte [] buffer2 = new byte[1];
String filename = "";
ASCIIEncoding asci = new ASCIIEncoding();

while (true)
{
    int k = networkStream.Read(buffer2, 0, buffer2.Length);
    filename = filename+asci.GetString(buffer2, 0, k); 
    if (k == 0) break;
}

using (Stream fileStream = File.OpenWrite("C:/Users/Laptop/Documents/" + filename))
{
    while (true)
    {
        thisRead = networkStream.Read(dataByte, 0, blockSize);

        fileStream.Write(dataByte, 0, thisRead);
        if (thisRead == 0) break;

    }

thanks. i think i dont know how to say or illustrate 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-05-27T01:54:33+00:00Added an answer on May 27, 2026 at 1:54 am

    You have to send something that indicates the end of the filename. The server receives the filename as long as this or these stop characters are not received and it receives the payload afterwards.

    For example, HTTP uses \r\n\r\n to mark the end of the HTTP header.

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

Sidebar

Related Questions

I am trying to implement a Client/Server model using TCpClient , with its Networkstream.Write()/Read()
Possible Duplicate: Not possible to launch a file on a network using Java Desktop?
I am trying to configure a network connection using ConfigurationManager.ProcessConfiguration, with the configuration file
Using a StreamWriter to write to a NetworkStream , and a StreamReader to read
I am using socket programming in vb.net to create a server client remoting application.
I want to serialize a 'Player' class and send it over my network stream
I'm trying to create a chat with file transfer application using TCPSocket and here
I have developed a small server that recives connections (using basically the example here:
I am trying to model a network using C++. I have a struct called
I am streaming a MP3 over network using custom feeding code, not AVAudioPlayer (which

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.