Questions tagged [tcpclient]

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

2318 questions
12
votes
4 answers

Loop until TcpClient response fully read

I have written a simple TCP client and server. The problem lies with the client. I'm having some trouble reading the entire response from the server. I must let the thread sleep to allow all the data be sent. I've tried a few times to convert this…
jim
  • 7,748
  • 11
  • 71
  • 144
12
votes
5 answers

TcpClient.GetStream().DataAvailable returns false, but stream has more data

So, it would seem that a blocking Read() can return before it is done receiving all of the data being sent to it. In turn we wrap the Read() with a loop that is controlled by the DataAvailable value from the stream in question. The problem is that…
James
  • 1,601
  • 1
  • 18
  • 23
12
votes
1 answer

When to use TcpClient.ReceiveTimeout vs. NetworkStream.ReadTimeout?

When programming a TCP server I would like to set the timeout period for reading the request from the client: var tcpClient = tcpListener.AcceptTcpClient(); var networkStream = tcpListener.GetStream(); tcpClient.ReceiveTimeout =…
Dio F
  • 2,319
  • 1
  • 19
  • 38
11
votes
5 answers

What happens if you break out of a Lock() statement?

I'm writing a program which listens to an incoming TcpClient and handles data when it arrives. The Listen() method is run on a separate thread within the component, so it needs to be threadsafe. If I break out of a do while loop while I'm within a…
dlras2
  • 8,048
  • 5
  • 46
  • 89
11
votes
1 answer

AuthenticateAsClient: System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream

Due to Heartbleed, our Gateway Server was updated and this problem presented itself. Due to POODLE, SSLv3 is no longer supported. Note, the problem is only present on Win7+ boxes; WinXP boxes work without issue (same code, different OS = problem);…
Bret
  • 2,193
  • 4
  • 18
  • 27
11
votes
2 answers

Why does NetworkStream Read like this?

I have an application that sends messages that are newline terminated over a TCP socket using TCPClient and it's underlying NetworkStream. The data is streaming in at roughly 28k every 100ms from a realtime data stream for monitoring. I've stripped…
paquetp
  • 1,593
  • 10
  • 19
11
votes
2 answers

Is it possible to convert between Socket and TcpClient objects?

Here's another C#/.NET question based merely on curiousity more than an immediate need ... If you had a Socket instance and you wanted to wrap it in the higher-level TcpClient class, is that possible and how would you do it? Conversely if you have…
Neil C. Obremski
  • 15,617
  • 20
  • 62
  • 90
11
votes
1 answer

Specify the outgoing IP address to use with TCPClient / Socket in C#

I've a server with several IP Addresses assigned to the network adapter. On that server is a client app to connect to another server app via TCPClient. For all outgoing communications my servers default IP address is being used, however for this one…
Dave Hogan
  • 3,165
  • 4
  • 28
  • 53
11
votes
2 answers

Android TCP connection best practice

I am working on an Android application that requires a TCP connection to a TCP server(Written in Node.js) My Android TCP client is working an can send messages back and forth. My spesific questions is: What is the best way to handle a TCP…
Emil
  • 146
  • 1
  • 1
  • 5
10
votes
2 answers

asyncio server and client to handle input from console

I have an asyncio TCP server that take messages from client, do stuff() on server and sends texts back. Server works well in the sense that receives and sends data correctly. Problem is that I can't takes messages back from server in the client…
BangTheBank
  • 651
  • 2
  • 9
  • 24
10
votes
1 answer

C# - an established connection was aborted by the software in your host machine Error

I am building a Mock Server using TCPListener. When I tried to debug my code by running the client, I was able to read the request on the server. But on the client side, an exception is being thrown. Here is the exception I got from the…
Ray
  • 597
  • 1
  • 6
  • 17
10
votes
3 answers

Cancel C# 4.5 TcpClient ReadAsync by timeout

What would the proper way to cancel TcpClient ReadAsync operation by timeout and catch this timeout event in .NET 4.5? TcpClient.ReadTimeout seems to be applied to the sync Read only. UPDATE: Tried tro apply the approach desribed here Cancelling an…
miksh
  • 159
  • 3
  • 9
10
votes
1 answer

How to detect a Socket Disconnect in C#

I'm working on a client/server relationship that is meant to push data back and forth for an indeterminate amount of time. The problem I'm attempting to overcome is on the client side, being that I cannot manage to find a way to detect a…
DigitalJedi805
  • 1,448
  • 3
  • 15
  • 39
9
votes
3 answers

What conditions cause NetworkStream.Write to block?

Will NetworkStream.Write block only until it places the data to be sent into the TCP send buffer, or will it block until the data is actually ACK'd by the receiving host? Note: The socket is configured for blocking I/O. Edit: Whoops, there's no such…
David Pfeffer
  • 36,331
  • 28
  • 120
  • 198
9
votes
1 answer

SslStream equivalent of TcpClient.Available?

Based on the advice of @Len-Holgate in this question, I'm asynchronously requesting 0-byte reads, and in the callback, accept bytes the available bytes with synchronous reads, since I know the data is available and won't block. This seems so…
Jason Kleban
  • 18,057
  • 15
  • 68
  • 116