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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:06:49+00:00 2026-05-31T20:06:49+00:00

I have a server-client application [TCP sockets, .NET 4.0].. the application about : do

  • 0

I have a server-client application [TCP sockets, .NET 4.0]..

the application about :

  • do the commands that received from the client
  • receives files
  • send a screenshot image
    the application should do the 3 tasks in the same time

    After i done that and it worked .. i realized that these kind of application should use one port for all tasks .. like Radmin and netsupport .. etc
    but i used 3 ports .. one to keep receiving commands any time the client sends. and one for receiving files .. and one if the client asked for a screenshot

    so is it fine to use 3 ports for a network application? ..

    I’ve tried to create 3 sockets on the client side to connect to server on the same port (ex:9090)
    but when i tried to send a file from the client .. the server received the bytes in Job function that’s should receives the commands only… so it looks like i can’t use one port for those tasks
    so is it possible use one port for all of the three tasks that they may work at the same time?

        private void ClientAccept()
        {
            while (true)
            {
                Socket client = server.Accept();
                Console.WriteLine(client.RemoteEndPoint + " has connected");
                NetworkStream stream = new NetworkStream(client);
                StreamReader reader = new StreamReader(stream);
                string line = reader.ReadLine();
                if (line == "1")           //it means its a command socket
                {
                    thJob = new Thread(Job);
                    thJob.Start(cmdClient);
                }
                else if(line=="2")        //its a data socket
                {
                    FileTransfer ft = new FileTransfer(client);
                }
             }
          }
    
        private void Job(object o)
        {
            Socket s = (Socket)o;
            StreamReader sr = new StreamReader(new NetworkStream(s));
            string cmd = null;
            while ((cmd = sr.ReadLine()) != null)
            {
                //bla bla
            }
        }
    

    Added question:

    lets say the server has one port.
    the client connect to server for commands .. let’s call it cmdClient which its port is 11589
    then a Job Thread started for this client like the code up.
    then the client connect with another socket to the server .. dataClient which its port is 1800
    then when i use the dataClient to send a file .. the server receives the bytes at the job Method .. !! why does that happene?

    • 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-31T20:06:50+00:00Added an answer on May 31, 2026 at 8:06 pm

      Yes, it is wise to use multiple ports when doing file transfers. It would require a quite advanced protocol to use the same port and still keep the application response (as you still have to be able to send commands during file transfers).

      But I do not recommend you to use three fixed ports. Use one port for all commands and an arbitrary number of ports for the file transfers.

      A file transfer would look like this:

      1. (CmdPort) Client -> Server Hey I want to transfer file XXX with size YYYY
      2. (CmdPort) Server -> Client Roger, connect to port 8217 and transfer the file
      3. (8217) Client -> Server Connects, transfer the entire file, disconnect
      4. (8217) Server Checks that the transferred size matches the one specified in step #1

      That allows you to transfer several files at the same time. Let the server create a new listening socket using port 0. It tells the OS to select a free port. Then use Socket.LocalEndpoint to find out the port before sending it back in step #2.

      The specified approach also lets you take advantage of Socket.SendFile which is probably the most effective and fastest way to send files using .NET.

      (FTP uses the same approach, as do bittorrent. You might have used a file manager when downloading files from the web. They takes a more extreme approach and splits up the file download over multiple sockets to get around web server bandwidth throttling.)

      update in response to a comment:

      my application also send folders , a folder may has 2000 files , many files size may equals to less than a kilo byte, it would be a huge mistake to connect for each file .. or maybe i should connect once for each task (a folder/ a file)

      You did not specify that information in the original question, which made me assume that you only transfer one file at a time.

      Batch transfers would work in the same way, just change so that step #1 sends a list of filename+size and then send all files after each other in step #3.

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

    Sidebar

    Related Questions

    I have a client server application that sends XML over TCP/IP from client to
    I have a server application that receives some special TCP packet from a client
    I currently have an application that sends XML over TCP sockets from windows client
    I currently have a TCP server application written in .Net that receives and submits
    i have file transfer application (Server-Client) TCP [.net 4] why is backgroundworker gives me
    I currently have a client-server application that involves a Silverlight client and a .NET
    I have a .NET 3.5 server application that usually has about 8 clients. I'm
    i have a server - client application that runs on java 1.3; i want
    We have a client/server application with a rich client front end (in .Net) and
    We have application that involves C++ socket server, Flash client that communicates with C++

    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.