tcpclient

TcpClient.NetworkStream Async operations - Canceling / Disconnect

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-05 04:33:06
问题 Disclaimer: My C# isn't even close to as good as my C++ I am trying to learn how to do async sockets in C# in order to write a test app for a component of mine. I read about a variety of methods, but it seems the most modern is to use TcpClient, get the NetworkStream from it, and call async methods on the NetworkStream that return Task. So, I set off on my adventure. It is not clear how to cancel the async methods properly or if I need to. Am I supposed to manually cancel them when I want to

Xamarin.Forms - TcpClient connection fails with System.Net.Sockets.SocketException (0x80004005): Network is unreachable

不羁岁月 提交于 2020-01-03 06:41:39
问题 Background: I am running a cross-platform Xamarin.Forms app on a Nexus 7 (Android API level 22) that is configured to (in order): Connect to my WiFi network Connect to a Python script that runs on the router/gateway ( 10.0.0.0/5000 ) Connect to an A2DP Bluetooth audio receiver on startup. My development machine is running Windows 7 with Visual Studio 2019 Preview (v16.0.0 Preview 1.1) , Xamarin.Forms (v3.4.0.1008975) , and Xamarin.Android (v28.0.0) . The WiFi network is hosted by a Raspberry

Async socket client using TcpClient class C#

佐手、 提交于 2020-01-02 12:53:12
问题 I have implemented a socket client using TcpClient class. So I can send and receive data, everything works good. But I ask some of the guru's out there :) Is there something wrong with my implementation? maybe there is a better way of doing things. In particular, how do I handle disconnects? Is there some indicator (or maybe I can write one myself) that tells me that socket has disconnected? I also have looked into async await features of Socket class, but can't wrap my head around

Bypass the proxy using TcpClient

喜你入骨 提交于 2020-01-01 19:58:15
问题 I'm trying to write a local proxy application. I know how proxy applications work in theory. I've done everything related to handle incoming connections. But the problem is how should I send request which client requested to specified Url. When I try to create a connection with TcpClient to specified Url and port, it throws following exception : No such host is known Edit : I think I should bypass the proxy something like FireFox is doing even system proxy set. Any idea will be helpful.

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

Does TcpClient write method guarantees the data are delivered to server?

北城以北 提交于 2020-01-01 00:27:47
问题 I have a separate thread on both client and server that are reading/writing data to/from a socket. I am using synchronous TcpClient im (as suggested in documention): https://msdn.microsoft.com/cs-cz/library/system.net.sockets.tcpclient%28v=vs.110%29.aspx When connection is closed .Read()/.Write() throws an exception. Does it mean that when .Write() method does not throw the data were delivered correctly to the other party or do I need to implement custom ACK logic ? I read documentation for

Connection from linux to windows via tcp

只愿长相守 提交于 2019-12-31 07:14:06
问题 I have a tcp server application on windows (c#) wich accepts any connection by the port 3000 I have a tcp client application on linux(ubuntu)(c++) wich send a simple text by the port 3000 I also have a client on windows and a server on linux, i works perfectly sending the text: from linux to linux from windows to windows from windows to linux the problem is that when i try to send from linux client to windows server my c++ application on linux tells me that the host doesn't exist i already

EOF in async_read() in boost::asio

一曲冷凌霜 提交于 2019-12-30 05:59:08
问题 When the async_read_some() returns an exception of EOF does it mean the server stopped sending data or does it mean the connection is closed. I'm having this confusion as I cant find a method to know if the client has received all data from server. 回答1: It indicates the connection has closed. Although documented elswhere it is still applicable: An error code of boost::asio::error::eof indicates that the connection was closed by the peer. If a client needs to know that all data has been

Read SSL Certificate Details on WP8

我与影子孤独终老i 提交于 2019-12-30 04:58:08
问题 I want to read certificate details (e.g. expiration date or CN) for security reasons. Usually there are some properties in network classes available, that allow to check the certificate. This is missing in WP8 implementations. Also I tried to create an SslStream but also there is no way to get any certificate detail like the RemoteCertificate on .net 4.5. var sslStream = new SslStream(new NetworkStream(e.ConnectSocket)); The SslStream is missing everything relating security. So it looks like

TCP client connection freezes program

僤鯓⒐⒋嵵緔 提交于 2019-12-25 18:36:20
问题 I'd like to have an asynchronous continuous ping request on a ip + port. The problem is, when the targeted server is offline, the whole program freezes during request time. But this shouldn't happen. This is my ping function which is called once when starting the program. It should do a ping request every 3 seconds. public async void Start(string ip) { Stopwatch watch = new Stopwatch(); while (true) { watch.Restart(); using (TcpClient tcp = new TcpClient()) { //try to connect to a closed port