Click here to Skip to main content
15,745,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a TCP client that I need to Listen and send responses. What’s the best way to achieve this with c#?
I’ve done something in the past but I was the client, in this situation I need to be the server. I’ve been searching a way to connect to the client through a given port and listen/send data….but with no results….

Here's my code so far....

private void ListeningThread() // let's listen in another thread instead!!
           int port = 12345; // change as required

           this.listener = new TcpListener(IPAddress.Any, port);

           catch (Exception e) { MessageBox.Show("couldn't bind to port " + port + " -> " + e.Message); return; }

           while (true)


Now I need, in the while cicle, to receive data and convert it to a string...
Updated 6-Jun-13 1:29am
Volynsky Alex 6-Jun-13 6:54am    
Hi marco.constantino

This article: describes a library that provides an easy to use a TCP server component for the .NET environment that does not have the limitations ...


1 solution

I guess you are talking about TcpListener Class[^].

Also refer - A TCP/IP Server written in C#[^].
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900