tcpclient

Server multithreading overkill?

I'm creating a server-type application at the moment which will do the usual listening for connections from external clients and, when they connect, handle requests, etc. At the moment, my implementation creates a pair of threads every time a client connects. One thread simply reads requests from the socket and adds them to a queue, an...

Do I have to store a TcpClient even though I only care about its stream?

A new instance of a TcpClient connects to a remote host. Its NetworkStream is retrieved and stored. Do I have to store the TcpClient itself as well to make sure it is not garbage collected? In case you're going to answer "You have to store it to be able to dispose it": In my specific case, the TcpClient is usually living for a long time...

Jumbled byte array after using TcpClient and TcpListener

I want to use the TcpClient and TcpListener to send an mp3 file over a network. I implemented a solution of this using sockets, but there were some issues so I am investigating a new/better way to send a file. I create a byte array which looks like this: length_of_filename|filename|file This should then be transmitted using the above m...

How do i judge when the NetWorkStream finishes by using .net TcpClient to communicate

I try to use stream.DataAvailable to judge if it is finished,but sometimes the value is false but after a little while it is true again,i have to set a counter and judge the end by the symbol '>' like this int connectCounter = 0; while (connectCounter < 1200) { if (stream.DataAvailable) { while (stream.DataAvailable) ...

How much buffer does NetworkStream and TcpClient have?

Hello, We are writing a TCPServer and Client program. How much space is there in the TcpClient buffer? Like, at what point will it begin to throw away data? We are trying to determine if the TcpClient can be blocking or if it should go into it's own background thread(so that the buffer can not get full).. ...

There's a black hole in my server (TcpClient, TcpListener)

Hi, I'm trying to build a server that will receive files sent by clients over a network. If the client decides to send one file at a time, there's no problem, I get the file as I expected, but if it tries to send more than one I only get the first one. Here's the server code: I'm using one Thread per connected client public void Proce...

How to pass a cstring from Delphi

I'm writing a tcp client in Delphi for a server that has a series of messages defined as c structs. Below is an example conversion of one of the messages: struct { int32 Reserved; cstring Name; int32 flags; } msg1 = record Reserved : integer; Name : cstring???; flags : integer; end Googling the type tell...

C# TcpClient, getting back the entire response from a telnet device

I'm writing a configuration tool for a device that can communicate via telnet. The tool sends a command via TcpClient.GetStream().Write(...), and then checks for the device response via TcpClient.GetStream().ReadByte(). This works fine in unit tests or when I'm stepping through code slowly. If I run the config tool such that it performs ...

Cocoa NSStream TCP connection to FTP

Hi, I'm new to Cocoa, but not to programming. Recently I decided I wanted to write a FTP client for Mac, and so I first made it in the language I'm most comfortable in (on Windows), and then moved on to Cocoa when I had the workings of FTP communications down. My question is (apparently) a bit controversial: How do I establish a read/w...

Is TcpClient BeginRead/Send thread safe?

Using a dotNET TcpClient if I have called an asynchronous BeginRead() on the associated network stream can I still call Write() on that stream on another thread? Or do I have to lock() the TcpClient in the code that is called back from the BeginRead and the code that does the send? Also if I close the TcpClient with: client.GetStream(...

TCP Connection Creation and Closing Event Hooking

Dear Devs I would like to write an application that tells when a tcp port opened and closed on windows platform please if some can give me piece of code or sample my preference is C# code. Regards ...

How do I get client ip address using TcpClient?

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 tried: Console.WriteLine(tcpClient.Client.RemoteEndPoint.ToString()); Console.WriteLine(tcpClient.Client.LocalEndPoint.ToString()); var networkStream = tcpClient.GetStream(); var pi = n...

How to use Tor control protocol in C#?

I'm trying to send commands to the Tor control port programmatically to make it refresh the chain. I haven't been able to find any examples in C#, and my solution's not working. The request times out. I have the service running, and I can see it listening on the control port. public string Refresh() { TcpClient client = new TcpClien...

TcpListener is queuing connections faster than I can clear them

As I understand it, TcpListener will queue connections once you call Start(). Each time you call AcceptTcpClient (or BeginAcceptTcpClient), it will dequeue one item from the queue. If we load test our TcpListener app by sending 1,000 connections to it at once, the queue builds far faster than we can clear it, leading (eventually) to tim...

multiple threads writting to a same socket problem

Hi: My program uses sockets for inter-process communication. There is one server listening on a socket port(B) on localhost waiting for a list of TCP clients to connect. And on the other end of the server is another a socket(A) that sends out data to internet. The server is designed to take everything the TCP clients send him and forwa...

Searching for patterns to create a TCP Connection Pool for high performance messaging

I'm creating a new Client / Server application in C# and expect to have a fairly high rate of connections. That made me think of database connection pools which help mitigate the expense of creating and disposing connections between the client and database. I would like to create a similar capability for my application and haven't been...

Should TcpClient be used for this scenario?

I have to communicate with an iPhone. I have its IP Address and the port (obtained via Bonjour). I need to send a header that is “0x50544833” (or similar, It’s an HEX number), then the size of the data (below) and then the data itself. The data is just a string that looks like this: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE pl...

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 lock() statement, will the lock be released? If not, how do I accomplish this? Thanks! (A...

.NET equivalent of recv?

I have a portion of C code that I am trying to port over to C#. In my C code, I create a socket and then issue a receive command. The receive command is void receive(mysocket, char * command_buffer) { recv(mysocket, command_buffer, COMMAND_BUFFER_SIZE, 0); } Now, the command buffer is returned with new values including command_bu...

Ruby background service

I have a TCPclient written on Ruby. I want to use it in background. Currently it has a loop: loop do end So i can run a client, and it works forever. Is there a way to run in as a service, and write a pid to file, then i'll able to kill that process by pid? ...