tcpclient

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 an instance of TcpClient, is it possible to get the underlying Socket? ...

TcpClient field of abstract base class constantly being disposed

Hi, I have an abstract base class with a TcpClient field: public abstract class ControllerBase { internal protected TcpClient tcpClient; It has a method to setup a connection: private void setupConnection(IPAddress EthernetAddress, ushort TcpPort) { if (this.tcpClient == null || !this.tcpClient.Connected) { ...

Does TcpListener.AcceptTcpClient throw uncritical exceptions?

In my application, I currently stop listening when AcceptTcpClient (or EndAcceptTcpClient) throws an exception. Typically exceptions are thrown when I stop the listener (socket error 10004) or when I disconnect the network adapter. try { while (true) { TcpClient client = listener.AcceptTcpClient(); // omitted: st...

C# Reading 'Zip' files with FileStream

I have written a program that will etablish a network connection with a remote computer using TCPClient I am using it to transfer files in 100k chunks to a remote .net application and it inturn then writes them to the HardDrive. All file transfers work good except when it comes to ZIP files - it is curious to note that the reasembled fil...

No connection could be made because the target machine actively refuses it.

Hello, I'm working on a simple hello world TCP/IP client server app in C# and am unable to get my client to connect. Can anyone offer any additional troubleshooting steps? I'm starting to run out of ideas... Here are the relevant sections of code: server: Console.Out.WriteLine("About to bind address"); IPAddress ipAd = IPAddress.Pa...

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); ...

How can I use "using" in C# without getting "InvalidOperationException"?

I am trying to replce the follwing code that works fine TcpClient oC = new TcpClient(ip, port); oC = new TcpClient(ip, port); StreamReader messageReader; try { messageReader = new StreamReader(oC.GetStream(), Encoding.ASCII); reply = messageReader.ReadLine(); } with try { using (messageReader = new StreamReader(oC.GetStream...

What is the preferred way to handle this TCP connection in C#?

I have a server application (singleton, simple .NET console application) that talks to a GlobalCache GC-100-12 for the purpose of routing IR commands. Various .NET WinForm clients on the local network connect to my server application and send ASCII commands to it. The server application queues these ASCII commands and then sends them to ...

SslStream on TCP Server fails to validate client certificate with RemoteCertificateNotAvailable

This question is all about solving a SslPolicyError.RemoteCertificateNotAvailable error. I have developed a TCP Server with SSLStream and a TCP Client for the other end. I authenticate the server with: sslStream.BeginAuthenticateAsServer I authenticate the client with: sslStream.BeginAuthenticateAsClient I am loading my client c...

Connect with TTcpClient through a http proxy

Hi all, How can i connect to a server through a http proxy server in delphi? What about SOCKS5 proxy? Google doesn't have any suggestion! ...

How to deal with delays on telnet connection programmatically?

Hi all, I utilize TcpClient class to implement a telnet connection. What I don't know is how to determine the end of response. It seems that once DataAvailable property is true, I read the data from Stream and DataAvailable is then temporarily set to false while buffer is being filled with another chunk of data but I think is all read an...

C# How do I stop a tcpClient.Connect() process when i'm ready for the program to end? It just sits there for like 10 seconds!

This is one of my first issues. Whenever I exit out the program, tcpClient.Connect() takes forever to close. I've tried a ton of things, and none of them seem to work. Take a look at the CreateConnection() thread, if the client isn't connected yet... and I close the program, it takes forever to close. If it IS connected, it closes immed...

Ensure streamreader doesn't hang waiting for data

The code below reads everything there is to read from tcp client stream, and on the next iteration it will just sit there on the Read() (i'm assuming waiting for data). How can I ensure it doesn't and just returns when there's nothing there to read? Do I have to set low timeout, and respond to an exception when it fails out? Or there's a...

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 kernel reserves a unique port for us sd_server = socket(PF_INET, SOCK_STREAM, 0); bind(...

How do I get the length (i.e. number of characters) of an ASCII string in VB.NET?

I'm using this code to return some string from a tcpclient but when the string comes back it has a leading " character in it. I'm trying to remove it but the Len() function is reading the number of bytes instead of the string itself. How can I alter this to give me the length of the string as I would normally use it and not of the arra...

not connecting to server problem in C#

I am running a client/server application. I use a textbox to let the user type in the IP address and port. I try to connect to the server, using 127.0.0.1 and there is no problem. After that I tried using 192.168.2.102 (NAT ip address of this computer), and it fails. Any idea why? the code I am using is: (this the the part that connects...

What is the best way to wait for a TcpClient data to become available in .NET?

while (TcpClient.Client.Available == 0) { Thread.Sleep(5); } There is a better way to do this? ...

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 back function looks like this... private static void AcceptClient(IAsyncResult asyncResul...

Read() blocking problem

I'm developing a server application in C#. Clients can connect to the server and make various requests. Currently, when a client connects I spawn a new thread to handle the request(s). I'm using the TCPClient class to handle client connections. My server works as follows: Client connect to server with a request Server handles request S...

Java: Connection refused but netstat says otherwise

I have several nodes acting as both servers and clients using Java's TCP sockets, i.e., Socket and ServerSocket. Each node uses persistent connections to communicate with 4 to 10 neighbors. However, sometimes a node (node1) may throw the following exception when trying to connect to another node (node2): java.net.ConnectException: Conne...