tcpclient

Sending Multiple Commands in TCPClient

Hi, I am trying to use private TcpClient tcpClient; in a class and every time when I send a command like LIST, RETR, STOR, I used to lock the TCPClient for that particular time of execution of commands and getting response. Now when I send the other command in between the one is executing, It isn't able to lock that tcpclient instan...

how to keep multiple Java HttpConnections open to same destination

We are using HttpURLConnection API to invoke a REST API to the same provider often (kind of an aggregation usecase). We want to keep a pool of 5 connections always open to the provider host (always the same IP). What is the proper solution? Here is what we tried: System.setProperty("http.maxConnections", 5); // set globally only once...

which time out value determins how long will the idle tcp connection will be closed

after the connection has been established, and the two sides have no communication, which timeout value determins the idle connection be closed? ...

NetworkStream.Read delay .Net

I have a class that inherits from TcpClient. In that class I have a method to process responses. In that method I call I get the NetworkStream with MyBase.GetStream and call Read on it. This works fine, excpet the first call to read blocks too long. And by too long I mean that the socket has recieved plenty of data, but won't read it un...

How to close a TcpClient when the other end has been closed in .NET?

I have a class that handles TcpClients. What the class should do is: while the other end has not done a graceful close or we are stopping { receive a request process it send response } As I don't know when the other client will send a request I can not do a Read with a timeout set, so what I have un...

TcpClient and StreamReader blocks on Read

Here's my situation: I'm writing a chat client to connect to a chat server. I create the connection using a TcpClient and get a NetworkStream object from it. I use a StreamReader and StreamWriter to read and write data back and forth. Here's what my read looks like: public string Read() { StringBuilder sb = new StringBuilder(); try...

C#: Alternative to NetworkStream.Read that indicates remote host has closed the connection?

With regards to handling a TCP/IP connection using the TcpClient class, is there an alternative for checking whether the remote host has closed the connection other than waiting for the NetworkStream.Read method to return a 0? ...

Should I always call TcpClient.EndConnect (even when connection fails?)

C# has several useful classes for networking tasks such as TcpClient and WebClient. Both have BeginX methods (BeginConnect and BeginGetResponse respectively) that according to MSDN should always be followed by EndX. Both accepts a delegate that is called once the operation is complete. However, say we fail to establish a connection, and...

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 application I'd like the outgoing communication to be send out on another local IP addre...

StreamWriter sending null messages when closing

I've written a simple chat program to experiment with some basic tcp/socket concepts. For some reason I've found that when I close my writer stream (which I am getting from the TcpClient.GetStream() function) it will send one final null message to my server. To top it all off it doesn't do this if I send one final message over the stream...

if i have already connected to the server. then how i show exception saying it is already connected

how to add in exception showing the input has to be enter, if the user click on connect without entering any input? i would like the have a message box show if the user click on the connect button without entering the name, ip and port. [SOLVED] using System; using System.Collections.Generic; using System.ComponentModel; using System....

Chat system with one or two ways?

I'm trying con build a simple chat client/software (whole in on executable) wich start listen from the start on the port 5900 and when a client connect to that port the chat is established. The problem is that only the client can chat to the server, the server cannot answer the client because the connection is working in one way. The i...

C# NetworkStream.Read oddity

Can anyone point out the flaw in this code? I'm retrieving some HTML with TcpClient. NetworkStream.Read() never seems to finish when talking to an IIS server. If I go use the Fiddler proxy instead, it works fine, but when talking directly to the target server the .read() loop won't exit until the connection exceptions out with an error l...

Problems setting a TcpClient local endpoint in C#

Why won't the following code work in C#? var c1 = new TcpClient(new IPEndPoint(IPAddress.Any, 8787)); var c2 = new TcpClient(new IPEndPoint(IPAddress.Any, 8788)); c1.Connect("localhost", 8788); I get a "connection cannot be made because the target machine actively refused it". So, the TcpClient constructor doesn't appear to be binding...

How to find cause and of the SocketException with message that an established connection was aborted by the software in your host machine?

Hi All, I know the similar question may have been asked many times, but I want to represent the behavior I'm seeing and find if somebody can help predict the cause of this. I am writing a windows service which connects to other windows service over TCP. There are 100 user entities of this, and 5 connections per each. These users perfor...

Does the creation of TcpClient have much overhead?

Hello All. I tried to send/receive data by using TcpClient. I did two experiments and found something interesting. I setup the TcpListener in a server in Japan and the TcpClient in UK. I kept sending 500 bytes to the TcpListener and when TcpListener sends 10KB back to the TcpClient. I kept this send/receive looping for 500 times in eac...

.NET 3.5 C# TcpClient Reading Issues (Segment loss)

...

Is it expensive to do a WHOIS lookup using TcpClient.Connect() in C#?

A customer has asked that we do a dynamic whois lookup on the homepage of their ASP.NET site, based on the IP of the user accessing the site. The implementation would be something like what's described here: http://www.aspheute.com/english/20000825.asp However, I noticed that this code connects to whois.networksolutions.com. I am thin...

How can TcpClient implement IDisposable and not have a public Dispose method?

Just as the title says: How can TcpClient implement IDisposable and not have a public Dispose method? ...

[C#] TcpClient - waiting for data to become available.

In my C# application, I have a thread which basically continually reads from a TcpClient until told to stop. I use WaitHandles for this purpose, for example: private ManualResetEvent stopping; private void Receive() { while (!this.stopping.WaitOne(10)) { while (this.client.Available > 0) { // Read an...