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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:29:57+00:00 2026-06-13T15:29:57+00:00

Sorry for the really broad question, but I’d love an answer. For an idea

  • 0

Sorry for the really broad question, but I’d love an answer.

For an idea I want one computer to start a server on a local network, and have another computer connect to this server in order to exchange data.

My question is how to do this?

As an added question, does someone have good tutorials on the System.net class reference?

  • 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-13T15:29:59+00:00Added an answer on June 13, 2026 at 3:29 pm

    One solution is to use Sockets. For a server socket, you create a socket and then call bind, listen and accept. This can be accomplished asynchronously or by just blocking the thread.

    Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    server.Bind(new IPEndPoint(IPAddress.Any, port));
    server.Listen(3);
    Socket client = server.Accept();
    

    Now, client is the connection to the connected computer. Now you can use the Send method to actually send data between the two.

    string message = "hello there";
    byte[] bytes = Encoding.UTF8.GetBytes(message);
    byte[] lengthBytes = BitConverter.GetBytes(bytes.Length);
    client.Send(lengthBytes);
    client.Send(bytes);
    

    The lengthbytes is used because the other client might not know how many bytes we are transferring for a “complete message”, so we simply tell it.

    The client on the other hand uses the Connect method to connect to a running server, and Recive to get the bytes sent from the server.

    Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    socket.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), port));
    byte[] lengthBytes = new byte[4];
    socket.Receive(lengthBytes);
    int length = BitConverter.GetInt32(lengthBytes);
    byte[] messageBytes = new byte[length];
    socket.Receive(messageBytes);
    string message = Encoding.UTF8.GetString(messageBytes);
    Console.WriteLine(message);
    

    Send and Receive work both ways by the way.

    This is just scratching the surface though. There’s a lot of resources out there in the wild that goes over this, but perhaps this can be a stepping stone for you. You could for instance look into the SocketAsyncEventArgs class that is used for asynchronous communication, instead of blocking the thread when calling Receive.

    You should also look into sanitation of user provided data. Remember, the “length” is user provided since that is in the protocol that we just defined. We can’t tell the server to always send correct data, it might as well send -1 which will be bad when we try to allocate new byte[length]. Sanitation, or validation, of data is necessary so the client doesn’t crash or does bad things on our own computer.

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

Sidebar

Related Questions

Sorry if this is a really basic question but it's been really getting to
Really stupid question, sorry, but I can't find it on google (I'm sure it's
I'm really sorry. This must seem like an incredibly stupid question, but unless I
Really sorry to be asking a bit of an off topic question, but we've
Well. i'm really sorry for the fact that this question is easily testable, but
Im really sorry for asking such a newby question but I dont know what
I'm really sorry if this question has nothing to do on this site, but
Sorry for really simple question, but I wasnt able to find anything in the
i'm really sorry if this question have been asked before but I couldn't find
Sorry i really didn't know how to phrase the question any better but here

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.