tcplistener

Transferring files over TCP with CopyTo()

寵の児 提交于 2020-02-25 04:48:12
问题 I have a question regarding the CopyTo() method of the Stream class: https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.copyto This approach works for small file circa 15kb as I tried it, but anything higher (I tested with 2mbs, 4 mbs and so on) and it just hangs on the CopyTo() method. Can't really figure out why. Code sample: Server's handle client : public void HandleClient(object c) { string path = "some path"; using (TcpClient client = (TcpClient)c) { using (NetworkStream

Transferring files over TCP with CopyTo()

时光总嘲笑我的痴心妄想 提交于 2020-02-25 04:46:15
问题 I have a question regarding the CopyTo() method of the Stream class: https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.copyto This approach works for small file circa 15kb as I tried it, but anything higher (I tested with 2mbs, 4 mbs and so on) and it just hangs on the CopyTo() method. Can't really figure out why. Code sample: Server's handle client : public void HandleClient(object c) { string path = "some path"; using (TcpClient client = (TcpClient)c) { using (NetworkStream

Why can't i listen to remote connections?

眉间皱痕 提交于 2020-01-17 04:51:09
问题 I want to listen to connections from remote machines. However its not working. Using my browser i just simply connect to 127.0.0.1 and i know if i connected or not (both from the browser message and debugger). 127.0.0.1 works as does 127.0.0.2. But 192.x.x.x does not unless i use IPAddress.Parse("192.168.1.1") (assuming thats my local address). But any is suppose to work for any interface. Whats wrong with this? DoBeginAcceptTcpClient looks like this. The problem still exist for ports >1024.

Why can't i listen to remote connections?

落爺英雄遲暮 提交于 2020-01-17 04:51:07
问题 I want to listen to connections from remote machines. However its not working. Using my browser i just simply connect to 127.0.0.1 and i know if i connected or not (both from the browser message and debugger). 127.0.0.1 works as does 127.0.0.2. But 192.x.x.x does not unless i use IPAddress.Parse("192.168.1.1") (assuming thats my local address). But any is suppose to work for any interface. Whats wrong with this? DoBeginAcceptTcpClient looks like this. The problem still exist for ports >1024.

How to know if it is memory leak or not if Mem Usage in Task Manager keep increasing

帅比萌擦擦* 提交于 2020-01-14 19:01:55
问题 I wrote a small Server class which basically is a TcpListener wrapper and ThreadPool thread spawner. The threads run Server::ProcessMessage() which does some work sending messages to and fro and then quits at the end of it. But just before exiting the function, I also call TcpClient.GetStream().Close() and then TcpClient.Close(). I don't use any Mutex or ManualResetEvent WaitHandles. Tested the Client and Server, everything works except in task manager it shows the Mem Usage keep on

How do I fix the error “Only one usage of each socket address (protocol/network address/port) is normally permitted”?

故事扮演 提交于 2020-01-10 08:09:28
问题 I've done a lot of googling but not had much luck with my issues. I am new to network programming and trying to learn, I've attempted to set up a simple server & client that communicate (following an online tutorial located here -> http://tech.pro/tutorial/704/csharp-tutorial-simple-threaded-tcp-server) The issue I'm having is that I keep getting the exception "Only one usage of each socket address (protocol/network address/port) is normally permitted" when trying to start the TcpListener on

How many socket connections can a web server handle?

最后都变了- 提交于 2020-01-08 18:16:26
问题 Say if I was to get shared, virtual or dedicated hosting, I read somewhere a server/machine can only handle 64,000 TCP connections at one time, is this true? How many could any type of hosting handle regardless of bandwidth? I'm assuming HTTP works over TCP. Would this mean only 64,000 users could connect to the website, and if I wanted to serve more I'd have to move to a web farm? 回答1: In short: You should be able to achieve in the order of millions of simultaneous active TCP connections and

TcpListener: How can I detect a client disconnect?

别说谁变了你拦得住时间么 提交于 2020-01-01 05:14:06
问题 How can I detect when a client disconnects from the TcpListener ? Each of my clients is handled in a separate thread. 回答1: Look at NetworkStream.Read, or depending on what you are using in your code maybe TCPClient.GetStream is more appropriate, but basically the same answer. From the docs: This method reads data into the buffer parameter and returns the number of bytes successfully read. If no data is available for reading, the Read method returns 0. The Read operation reads as much data as

How does NetworkStream work in two directions?

一笑奈何 提交于 2019-12-31 02:55:10
问题 I've read an example of a Tcp Echo Server and some things are unclear to me. TcpClient client = null; NetworkStream netStream = null; try { client = listener.AcceptTcpClient(); netStream = client.GetStream(); int totalBytesEchoed = 0; while ((bytesRcvd = netStream.Read(rcvBuffer, 0, rcvBuffer.Length)) > 0) { netStream.Write(rcvBuffer, 0, bytesRcvd); totalBytesEchoed += bytesRcvd; } netStream.Close(); client.Close(); } catch { netStream.Close(); } When the server receives a packet (the while

Cancel NetworkStream.ReadAsync using TcpListener

℡╲_俬逩灬. 提交于 2019-12-28 18:39:03
问题 Consider the following simplified example (ready to roll in LinqPad, elevated account required): void Main() { Go(); Thread.Sleep(100000); } async void Go() { TcpListener listener = new TcpListener(IPAddress.Any, 6666); try { cts.Token.Register(() => Console.WriteLine("Token was canceled")); listener.Start(); using(TcpClient client = await listener.AcceptTcpClientAsync() .ConfigureAwait(false)) using(var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5))) { var stream=client.GetStream