.NET Framework class, providing client connections for TCP network services.
Questions tagged [tcpclient]
2541 questions
151
votes
6 answers
Connecting to TCP Socket from browser using javascript
I have a vb.net application that opens a socket and listens on it.
I need to communicate via this socket to that application using a javascript running on a browser. That is i need to send some data on this socket so that the app which is listening…

swordfish
- 4,899
- 5
- 33
- 61
142
votes
20 answers
In C#, how to check if a TCP port is available?
In C# to use a TcpClient or generally to connect to a socket how can I first check if a certain port is free on my machine?
more info:
This is the code I use:
TcpClient c;
//I want to check here if port is free.
c = new TcpClient(ip, port);

Ali
- 5,286
- 9
- 33
- 36
102
votes
10 answers
How to set the timeout for a TcpClient?
I have a TcpClient which I use to send data to a listener on a remote computer. The remote computer will sometimes be on and sometimes off. Because of this, the TcpClient will fail to connect often. I want the TcpClient to timeout after one second,…

msbg
- 4,852
- 11
- 44
- 73
82
votes
21 answers
Error: TCP Provider: Error code 0x2746. During the Sql setup in linux through terminal
I am trying to setup the ms-sql server in my linux by following the documentation
https://learn.microsoft.com/pl-pl/sql/linux/quickstart-install-connect-ubuntu?view=sql-server-2017
The SQL server status is Active (Running).
I am getting the…

Suba Nandhini K
- 821
- 1
- 6
- 3
43
votes
4 answers
How do I get a client's IP address from behind a load balancer?
I am using TcpClient to listen on a port for requests. When the requests come in from the client I want to know the client ip making the request.
I've…

brendan
- 29,308
- 20
- 68
- 109
37
votes
4 answers
Sending and receiving data over a network using TcpClient
I need to develop a service that will connect to a TCP server. Main tasks are reading incoming messages and also sending commands to the server in ten minutes, like a synchronize command. For example, I used the TcpClient object as shown…

dankyy1
- 1,094
- 2
- 16
- 32
37
votes
10 answers
How to check if TcpClient Connection is closed?
I'm playing around with the TcpClient and I'm trying to figure out how to make the Connected property say false when a connection is dropped.
I tried doing
NetworkStream ns = client.GetStream();
ns.Write(new byte[1], 0, 0);
But it still will not…

RoboDev
- 4,003
- 11
- 42
- 51
34
votes
2 answers
Async lock not allowed
Basically, I want to make multiple asynchronous requests to a tcp Server. I currently have a working client that is only synchronous and blocks the UI on every network call. Since multiple requests might occur at almost the same time, I tried to do…

Philippe Paré
- 4,279
- 5
- 36
- 56
27
votes
1 answer
TcpClient vs Socket when dealing with asynchronousy
This is not yet another TcpClient vs Socket.
TcpClient is a wrapper arround the Socket class to ease development, also exposing the underlying Socket.
still ...
On the MSDN library page for TcpClient class, one can read the following remark :
The…

darkey
- 3,672
- 3
- 29
- 50
27
votes
1 answer
How to properly use TcpClient ReadTimeout
After spending way more time than seems reasonable to find an answer to this simple question, I thought I would leave my results here so others don't have to jump through all the hoops and wrong paths that I had just followed.
The problem is that if…

Dunk
- 1,704
- 1
- 14
- 19
26
votes
3 answers
What is the correct way to read from NetworkStream in .NET
I've been struggling with this and can't find a reason why my code is failing to properly read from a TCP server I've also written. I'm using the TcpClient class and its GetStream() method but something is not working as expected. Either the…

Loudenvier
- 8,362
- 6
- 45
- 66
25
votes
3 answers
c# detecting tcp disconnect
I have two simple applications:
A Server application that waits on a specific tcp port for a client to connect. Then listens to what he says, send back some feedback and DISCONNECT that client.
A Form application that connects to the server…

nl-x
- 11,762
- 7
- 33
- 61
22
votes
3 answers
How to use SSL in TcpClient class
In the .NET framework there is a class TcpClient to retrieve emails from an email server. The TcpClient class has 4 constructors to connect with the server which take at most two parameters. It works fine with those servers which does not use SSL.…

Md Kamruzzaman Sarker
- 2,387
- 3
- 22
- 38
22
votes
5 answers
Stopping a TcpListener after calling BeginAcceptTcpClient
I have this code...
internal static void Start()
{
TcpListener listenerSocket = new TcpListener(IPAddress.Any, 32599);
listenerSocket.Start();
listenerSocket.BeginAcceptTcpClient(new AsyncCallback(AcceptClient), null);
}
Then my call…

Anthony D
- 10,877
- 11
- 46
- 67
21
votes
1 answer
What are the benefits of using TcpClient over a Socket directly?
I understand that a TcpClient is a wrapper around the socket class, and I can access the underlying socket if using the TcpClient, but what exactly does the wrapper do?
When using the TCPClient do i need to keep calling Receive() like I do with a…

Dermot
- 1,713
- 2
- 18
- 29