tcpclient

TcpListener/TcpClient stops processing data under certain circumstances

时间秒杀一切 提交于 2019-12-23 02:58:17
问题 I have an issue where, depending on the startup order of two network devices, I seem to lose the ability to receive data on one end. The setup is one small server written in C# (.NET 4.0) that listens to a specific port for data coming from an industrial scanner, communicating over TCP. The scanner connects to the server application just fine, and will send small chunks of data (serial numbers) which the server receives and processes. However, restarting (actually, cycling power, doesn't

Measure data transfer rate over tcp using c#

寵の児 提交于 2019-12-22 18:45:19
问题 i want to measure current download speed. im sending huge file over tcp. how can i capture the transfer rate every second? if i use IPv4InterfaceStatistics or similar method, instead of capturing the file transfer rate, i capture the device transfer rate. the problem with capturing device transfer rate is that it captures all ongoing data through the network device instead of the single file that i transfer. how can i capture the file transfer rate? im using c#. 回答1: Since you doesn't have

C# TcpClient reading multiple messages over persistent connection

别等时光非礼了梦想. 提交于 2019-12-22 17:51:48
问题 I'm trying to create a TCP Server & Client that will have a persistent connection so that the server and client at any point in time can notify each other of certain 'events'(so push instead of poll). I almost have everything working, clients can connect, connection is kept open and client and server can both write & read from the tcp stream. The problem is with the read, I've defined the message boundary by first sending 8 bytes that contain the length of the message. Once I've received it,

Pointer being freed was not allocated [Swift]

僤鯓⒐⒋嵵緔 提交于 2019-12-22 08:52:34
问题 I am trying to read long length String in TCP socket connection . For reading short length string it is working fine . but when i am trying to send long length base64 Encoded Image . it is crashing , i tried to increasing upto maxReadLength = 10000 , but still it is not working . Reading incoming message private func readAvailableBytes(stream: InputStream) { let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: maxReadLength) while stream.hasBytesAvailable { let numberOfBytesRead =

Indy TIdTCPClient receive text

 ̄綄美尐妖づ 提交于 2019-12-22 00:27:47
问题 I try to receive text in a idtcpclient but it does not work. This is the code that I use in a timer: procedure TForm1.Timer2Timer(Sender: TObject); var receivedtext:string; begin if idtcpclient1.Connected = true then begin with idtcpclient1 do begin if not IOHandler.InputBufferIsEmpty then begin try receivedtext := IOHandler.ReadLn; finally if receivedtext = '' = false then begin showmessage(receivedtext); idtcpclient1.IOHandler.InputBuffer.Clear; receivedtext := ''; end; end; end; end; end

TcpClient; NetworkStream; ReadAsync; C#

こ雲淡風輕ζ 提交于 2019-12-21 20:27:11
问题 Please excuse my lack of knowledge regarding Tasks and Async. Using the TcpClient class I am creating a connection with an available server: void async RunClientAsync() { TcpClient client = new TcpClient(); try { await client.ConnectAsync(IPAddress.Parse("1.1.1.1"), 8889); Task.Start(() => ReadClientAsync(client)); } catch (Exception ex) { HandleException(ex); } } // ----- void async ReadClientAsync(TcpClient client) { byte[] bf = new byte[2048]; try { while(true) { int br = await client

C# NetworkStream.Read oddity

↘锁芯ラ 提交于 2019-12-21 09:27:49
问题 Can anyone point out the flaw in this code? I'm retrieving some HTML with TcpClient. NetworkStream.Read() never seems to finish when talking to an IIS server. If I go use the Fiddler proxy instead, it works fine, but when talking directly to the target server the .read() loop won't exit until the connection exceptions out with an error like "the remote server has closed the connection". internal TcpClient Client { get; set; } /// bunch of other code here... try { NetworkStream ns = Client

Understanding the NetworkStream.EndRead()-example from MSDN

一曲冷凌霜 提交于 2019-12-21 09:07:30
问题 I tried to understand the MSDN example for NetworkStream.EndRead(). There are some parts that i do not understand. So here is the example (copied from MSDN): // Example of EndRead, DataAvailable and BeginRead. public static void myReadCallBack(IAsyncResult ar ){ NetworkStream myNetworkStream = (NetworkStream)ar.AsyncState; byte[] myReadBuffer = new byte[1024]; String myCompleteMessage = ""; int numberOfBytesRead; numberOfBytesRead = myNetworkStream.EndRead(ar); myCompleteMessage = String

How to use Proxy with TcpClient.ConnectAsync()?

半世苍凉 提交于 2019-12-21 06:08:47
问题 HTTP proxy support in .NET does not actually support the lower level classes like TcpClient or Socket. But I want to connect a TCPServer (ip, port) through HTTP proxy that support 'CONNECT' command. So I need to do the following steps: Connect to proxy. Send CONNECT Host:Port HTTP/1.1<CR><LF> Send <CR><LF> Wait for a line of response. If it contains HTTP/1.X 200 , the connection is successful. Read further lines of response until receive an empty line. It's connected to the outside world

TCP read and write from client and server

偶尔善良 提交于 2019-12-20 07:48:57
问题 I'm trying to make a client and server which can read and write info back and forth between each other. I can write from the client and server reads it but not vise versa and I have no idea why. Nobody on here seems to know when I asked before and I cant find anything online that works. If you know please tell me and not tell me to go read an article about TCP because it doesn't help at all. Client: namespace ExampleClient { public partial class Form1 : Form { public static bool IsConnected;