Questions tagged [tcpclient]

.NET Framework class, providing client connections for TCP network services.

2318 questions
129
votes
19 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
  • 4,868
  • 8
  • 31
  • 36
123
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,569
  • 5
  • 29
  • 57
83
votes
9 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,414
  • 10
  • 41
  • 71
73
votes
14 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://docs.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
  • 731
  • 1
  • 3
  • 3
39
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
  • 27,495
  • 18
  • 64
  • 106
36
votes
9 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…
Superdumbell
  • 4,439
  • 11
  • 40
  • 49
35
votes
5 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,054
  • 2
  • 16
  • 32
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,472
  • 3
  • 27
  • 45
26
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,676
  • 13
  • 19
25
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
  • 7,847
  • 6
  • 41
  • 58
23
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é
  • 3,813
  • 5
  • 27
  • 50
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,227
  • 11
  • 43
  • 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,673
  • 2
  • 17
  • 29
20
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,219
  • 2
  • 18
  • 33
18
votes
2 answers

How to let kernel choose a port number in the range (1024,5000) in TCP socket programming

When I run the following code: struct sockaddr_in sin; int addrlen; addrlen=sizeof(sin); memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr=inet_addr("123.456.789.112"); sin.sin_port=htons(0); // so that the…
Anonymous
  • 3,923
  • 10
  • 29
  • 37
1
2 3
99 100