tcpclient

TcpListener: How can I detect a client disconnect ?

How can I detect when a client disconnects from the TcpListener ? Each of my clients is handled in a separate thread. ...

Re-opening a closed NetworkStream?

Good morning, I am in need of some advice, I am using a networkStream, which is streaming from a TcpClient, all was working fine, but then I required the some functionality elsewhere, which requires the stream to be closed. I can't seem to find a way to re open the connection once it has been closed. Could anyone point me in the correct...

Example of messages to send to a telnet server

We have a unix box in our ofc. We usually telnet to this box and initiate commands on it. We usually do this from windows clients from the command prompt using the telnet.exe. We simply provide the ip of the unix box and it loads up a screen where we provide the login credentials. There is a default message before the login prompt saying...

Why won't TcpClient.Write throw an exception when writing to a closed connection (the first time)?

I have a simple program that uses TcpClient and SslStream to write data to a socket. To test it I ran the program over night so my program would open the connection, write nothing for a long time, so the firewall or remote server would close the connection. This morning I took a look at TCPView and verified the connection was closed ...

how to send objects or dataset in tcpclient connection using C# ?

i want to transfer an object or a data set from one computer and other i am sending strings using streamwriter and reader now i want send an object via this client connection so how do i send this object or a dataset using this connection ? Consider i want to send a dataset now what you people suggest ...

Tcp Client two way communication help

I want to communicate between two applications or winforms in C# using clients and server its like i want a server continiously listening to incoming messages from a client or clients and when the msg is received i want to reply back to the client that sent the information for processing can any one help with code example ...

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 show me if the TcpClient is disconnected. How would you go about this using a TcpClient? ...

Wavecom GSM modem as a TCP client

Hi. I've been trying to do TCP communication using my Wavecom Fastrack modem. What I want to achieve is make the modem connect to a specified TCP server port to enable me to transfer data to and from the server. I found some information on than in the user's guide. Basing on the information you can find on page 66 I created an applicatio...

How to use TCPListener (or other method) to bind to device on the network

I have a device with a network address of 192.168.xxx.xxx port xxxx. This is a valid address on my network. I have tried to use TCPListener to make the connection for the server but receive the error "Error..... System.Net.Sockets.SocketException: The requested address is not vali d in its context at System.Net.Sockets.Socket.DoBin...

tcpclient listening implementation

Hi: I am trying to implement a tcp client listening function. This means that after connection established with server, this tcp client just sit there and waiting for new data to arrive. Here is my code but when it runs, it complain about not been able to read anything from the network stream. But the server hasn't started sending data...

Java SocketChannel Eating my bytes

Hi, I created a SocketChannel to a remote server to send and receive messages on Tomcat. To receive messages from a remote computer, I used a thread dedicated to task (only this thread will read from the socket, nothing else). When some bytes are received at the SocketChannel (I keep polling the SocketChannel on non-blocking mode for n...

Using TCPClient with RAW FTP to retrieve file

I get the following message back when trying to retrieve a file using TCPClient and RAW FTP: "425 Failed to establish connection." I connect using : using (TcpClient client = new TcpClient("ServerName", 21)) using (NetworkStream stream = client.GetStream()) using (StreamReader reader = new StreamReader(stream)) ...

C# Discover the LocalEndPoint AddressFamily port number

When I establish a tcp connection to a server using the TcpClient class, is there any way to find out the source port of this connection? I am trying to implement the exec protocol and stderr port seems to always be source port + 1. ...

Thread to receive data from an ip and port

I would like to write a program to receive some data using tcpClient from a specified ip and port number. First time I did it using while(true). Friend of mine told me to use thread instead of while loop. So I did as he said. public static void receiveThread() { TcpClient tcpClient = new TcpClient(); try { tcpClient....

Creating an 802.11 transmitter and reading the data from a WiFi router.

There are 2 parts to this question. Feel free just to give me URLs to articles or suggest books, too, as the answer is probably a bit in depth for a quick forum response. 1) I need to sense the wattage flowing through a pair of wires and transmit data about it via 802.11. I guess a micro controller is involved, but I'm not sure where to...

.Net C# TcpClient / Socket HTTP Client Performance / Efficiency

Hi All, I'm writing an HTTP client using the .Net TcpClient / Sockets. So far, the client handles both Content-Length and chunked responses by iterating through the NetworkStream response (after writing a GET request to the TcpClient), parsing the headers and retrieving the relevant message body bytes / chunked bytes. To do this it us...

Problem with TCPListener

I have some kind of problem and I can't check this at home if its working or not. Here is the code using System; using System.Net; using System.Net.Sockets; using System.Threading; using System.IO; using System.Net.Security; class Program { private static IPAddress ipAddress = IPAddress.Parse("127.0.0.1"); private static int port = 600...

Receving and sending data in C#

Im still trying to improve a little bit what I wrote before. Now I faced a problem with receiving data. I have a program which I use to send string using tcpClient to a program in which Im listening on a specified port. It works fine so I decided to send data forward one more time public static void receiveThread() { while (true) ...

C#: Handling terminate signal in TCP handler thread?

I am using the TcpClient class in C#. Each time there is a new tcp connection request, the usual practice is to create a new thread to handle it. And it should be possible for the main thread to terminate these handler threads anytime. My solution for each of these handler thread is as follows: 1 Check NetworkStream's DataAvailable ...

Detecting client TCP disconnection while using NetworkStream class

A friend of mine came to me with a problem: when using the NetworkStream class on the server end of the connection, if the client disconnects, NetworkStream fails to detect it. Stripped down, his C# code looked like this: List<TcpClient> connections = new List<TcpClient>(); TcpListener listener = new TcpListener(7777); listener.Start()...