networkstream

How to check if TcpClient Connection is closed?

你。 提交于 2019-12-17 04:20:57
问题 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? 回答1: I wouldn't recommend you to try write just for testing the socket. And don't relay on .NET's Connected property either. If you want to know if the remote end

WebClient.DownloadString is 12 times faster than TcpClient?

六月ゝ 毕业季﹏ 提交于 2019-12-14 04:22:37
问题 It is now 8 hours and I am still trying to figure out. Code examples will be in VB.NET but I think they are also readable for C# users. Oh, and I accept C# solutions too. This takes maximum 50ms: Dim Data as String = wc.DownloadString("x.com") While this takes 600ms average: Dim client As New Net.Sockets.TcpClient client.NoDelay = True client.Client.NoDelay = True client.Connect(IP, 80) Dim ns As Net.Sockets.NetworkStream = client.GetStream Dim gbytes(70000) As Byte ns.Write(rbytes, 0, rbytes

How to stop reading from NetworkStream?

大城市里の小女人 提交于 2019-12-14 03:53:05
问题 I'm trying to read data from NetworkStream. I write next code: Imports System.Net Imports System.Net.Sockets Public Class Form1 Dim tcpclnt1 As New TcpClient Dim streamTcp1 As NetworkStream Dim DataBuffer(1024) As Byte 'Buffer for reading Dim numberOfBytes As Integer ' event for reading data from stream Dim evtDataArrival As New AsyncCallback(AddressOf DataProcessing) Private Sub Btn_Connect5000_Click(sender As Object, e As EventArgs)_ Handles Btn_Connect5000.Click ' Connecting to server

C# Streaming video over NetworkStream / TCPClient

不问归期 提交于 2019-12-13 07:13:07
问题 I am sending a video feed from an Xbox Kinect from a client program to a server. I have everything working but the problem is the frame rate. I'm thinking what is happening is it is sending faster than it can read. So when it can't send anymore it stores what it is about to send and waits until there is room in the buffer. The reason I think this is what is happening is because I can see the memory usage of the program steadily growing. Also because when I watch the video feed, I see

Counterpart of .NETs NetworkStream / SslStream in Delphi 7 [closed]

馋奶兔 提交于 2019-12-13 03:26:27
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I have written a secure TCP server in .NET. This was basically as simple as creating a TcpListener instance and wrapping the connected client's NetworkStreams with SslStreams. Now I need to access this TCP server with Delphi 7 (alternatively: Delphi 2007). I haven't found anything in the help, and a Google

StreamWriter won't flush to NetworkStream

时光总嘲笑我的痴心妄想 提交于 2019-12-12 21:20:49
问题 Using a StreamWriter to write to a NetworkStream , and a StreamReader to read the response. The app is sending commands and reading responses to a news server. Simplified code (sans error handling, etc.): tcpClient = new TcpClient(); tcpClient.Connect(Name, Port); networkStream = tcpClient.GetStream(); serverReader = new StreamReader(networkStream, Encoding.Default); serverWriter = new StreamWriter(networkStream, Encoding.ASCII) { AutoFlush = true }; // reads the server's response to the

Write() and Read() raw bytes from NetworkStream, data is difference at some bytes

牧云@^-^@ 提交于 2019-12-12 19:07:20
问题 I've written some code for sending byte[] array using NetworkStream with KNOWN size before sending, but the data sent and data received are difference at some positions. MAXSIZE is the known size of the data I want to send. public static void SendBytes(TcpClient clientSocket, byte[] outStream) { Debug.WriteLine("SendBytes() number of bytes: " + outStream.Length.ToString()); NetworkStream serverStream = clientSocket.GetStream(); serverStream.Write(outStream, 0, outStream.Length); /

Does one need to close both NetworkStream and TcpClient, or just TcpClient?

╄→尐↘猪︶ㄣ 提交于 2019-12-12 07:46:56
问题 I'm reading the documentation on TcpClient.Close() and noticed this: Calling this method will eventually result in the close of the associated Socket and will also close the associated NetworkStream that is used to send and receive data if one was created. So, correct me if I'm wrong but this says that if one calls Close() on the TcpClient that the NetworkStream will also be closed. So then why at the end of the code example are both Close() called? networkStream.Close(); tcpClient.Close();

.NET NetworkStream closed, how to be sure all data is read?

扶醉桌前 提交于 2019-12-11 06:28:30
问题 I've an open TCP connection, and reading using NetworkStream.BeginRead(). Once the connection is closed at either end, the callback is called and the stream object is useless - like documentation says, EndRead() throws IOException or ObjectDisposedException depending in this case on which end terminated the connection. Is it guaranteed that there isn't any data I'm missing just in between the last successful EndRead (and the re-BegingRead) and disconnection, particularly if I do it at my end?

Previous Data Remains on the Network Stream

纵饮孤独 提交于 2019-12-11 05:56:07
问题 I'm currently building a file transfer application with some logging features. What it does is, every time a client connects or disconnects it sends logs (string message) to the server. The logging part is working fine but when I try to send files, the program messes up. It seems that this is purely a server side issue. What happens is that the previous data; which is the string message for logging, sent from the client seems get stuck on the network stream. When I try to send a file after