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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:11:27+00:00 2026-05-26T03:11:27+00:00

Hello guys this method sending file on client machine private void StartServer() { TcpListener

  • 0

Hello guys this method sending file on client machine

        private void StartServer()
    {
        TcpListener lsn = new TcpListener(IPAddress.Any, 27015);
        Socket sck;

        try
        {
            while (true)
            {
                lsn.Start();
                sck = lsn.AcceptSocket();
                byte[] b = new byte[100];
                int k = sck.Receive(b);
                string recived = "";

                for (int i = 0; i < k; i++)
                {
                    recived = "" + recived + "" + Convert.ToChar(b[i]).ToString();
                }

                if (recived == "Version")
                {
                    string _ipPort = sck.RemoteEndPoint.ToString();

                    var parts = _ipPort.Split(':');
                    _IPAddr = IPAddress.Parse(parts[0]);
                    _Port = Convert.ToInt32(parts[1]);
                    sck.Send(System.Text.Encoding.ASCII.GetBytes("1.1.0.0"));
                }

                k = sck.Receive(b);
                recived = "";

                for (int i = 0; i < k; i++)
                {
                    recived = "" + recived + "" + Convert.ToChar(b[i]).ToString();
                }

                if (recived == "Update")
                {
                    fName = "Cannonball.mp3";

                    byte[] fileName = Encoding.UTF8.GetBytes(fName);
                    byte[] fileData = File.ReadAllBytes("D:\\Cannonball.mp3");
                    byte[] fileNameLen = BitConverter.GetBytes(fileName.Length);

                    clientData = new byte[4 + fileName.Length + fileData.Length];

                    fileNameLen.CopyTo(clientData, 0);
                    fileName.CopyTo(clientData, 4);
                    fileData.CopyTo(clientData, 4 + fileName.Length);

                    if (sck.Connected == true)
                    {
                        sck.Send(clientData);
                        sck.Close();
                    }

                }
            }
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message.ToString());
        }
    }

When its goes to last if statment does not doing nothing. I wrote this code

Socket sck1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        sck1.Connect(_IPAddr, _Port);
                        sck1.Send(clientData);

but visual studio gives error that cannot establish connection.
I tried 999 port which i knew was open sck1.Connect(_IPAddr, 999); and client recieved file.
Does anyone know how i can send file that remote endpoint(sck.RemoteEndPoint) which server got ?

  • 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-26T03:11:28+00:00Added an answer on May 26, 2026 at 3:11 am

    If sck1.Connect(_IPAddr, 999) connects to some socket on the server’s machine, then at least the value of _IPAddr is correct.

    Did you check what value _Port has when you are trying to connect? Does it match the port number the server is listening at?

    If these numbers match, you could try the following to test if your server is reachable:

    • Start the server application
    • On the client machine, open a browser and type: http://111.11.11.111:27015 (replace the 111’s with the actual IP address)
    • If the server accepts a socket at that time, the server is reachable and you’ll need to focus on the client application rather than the server.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hello guys i have this function for focus : fav[jj].setOnFocusChangeListener(new View.OnFocusChangeListener() { public int
Hello guys i am new about this implementing facebook into my app.I check developer's
Hello guys I have a question regardless a old code a client needed a
Hello guys I have a little trouble with the my method [HTTPost], please see
Hello guys on my blog I use this script: jQuery(document).ready(function () { jQuery(.postbox).hover(function ()
Hello guys I have this video tutorial on Ruby on Rails and I see
Hello I'm essentially trying to do this inside a new view window in SQL
I have this code: $abc = ' Hello Guys , Goodmorning'; I want to
Hello guys I have the following method: var usuario; usuario = UniapontaService.GetUsuarioUniapontaPlanejamentoEstrategico(x => x.IdUsuario
hello guys im using this second part of pagination script to show pagination; <?

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.