0

I need some help with TCP connection related stuff in C#. I need to figure out how to make a very basic connection between two endpoints and manage to send data between them. In my case it's a "server-side" program and a "client-side" program.

My problem is that I don't know how I go about making the client program listen for response after sending data. Do I need to have a TcpListener on the client side too? In which case, how do I use it?

Basically, I know how to make the client toss the ball and how to make the server catch it, and I think I know how to make the server toss the ball back, but I don't know how to make the client catch it. :/

Comments
  • 5
    To be honest there a like 7000 trillion examples about this available via any search engine and additionally I can guarantee you tahat here are also plenty of questions about this on Stack Overflow. Use the force of a search engine, please 🤗
  • 0
    I don't know C#/.NET, but "connection objects" are usually bidirectional.

    I have found following, by using Google:

    TcpClient client = new TcpClient("localhost", port);
    NetworkStream stream = client.GetStream();
    StreamReader reader = new StreamReader(stream);
    StreamWriter writer = new StreamWriter(stream) { AutoFlush = true };

    and you can use

    reader.ReadLine

    I would guess normal read works, too.
  • 0
    @moagggi Believe me, I've tried, but I figure that I'm either too dumb or just using the completely wrong keywords. :(

    @sbiewald I'll try and look over the docs again once I'm back at my computer and see if I can figure it out. :/
Add Comment