小编Jam*_* MA的帖子

What should I do to completely close the tcpClient connection with mcu?

I'm now working on a tcp socket connection to tcp server running in ESP32. It works fine for the communication, but I failed to close the connection. After searching for the solution on close/reset tcpClient, it seems that the proper way to close a tcpClient should be:

tcpClient.GetStream().Close();
tcpCLient.Close();
Run Code Online (Sandbox Code Playgroud)

The example in msdn also use this method.

But unforunately, it cannot really close the connection. As checked in the mcu, the connection has not been closed. And it will not …

c# sockets connection tcpclient

6
推荐指数
1
解决办法
1823
查看次数

在wpf项目中使用HttpClient上的await

我只是按照同步模式调用HttpClient的示例,它在Console应用程序中正常工作.

但是,当我将它移动到wpf应用程序时,程序挂起而没有任何返回.

我尝试通过构建一个单独的类来处理访问www.google.com的虚拟请求来隔离问题.

似乎应用程序在调用client.GetAsync时挂起,我可以知道在这种情况下是否有任何东西需要从控制台应用程序更改为wpf?

请找到控制台应用程序和wpf的来源,如下所示,

控制台应用 - 工作正常:

using System;
using System.Threading.Tasks;
using System.Net.Http;

namespace ca03
{
    static class action
    {
        static async Task<string> DownloadPageAsync()
        {
            // ... Target page.
            string page = "http://www.google.com/";

            // ... Use HttpClient.
            using (HttpClient client = new HttpClient())
            using (HttpResponseMessage response = await client.GetAsync(page))
            using (HttpContent content = response.Content)
            {
                // ... Read the string.
                string result = await content.ReadAsStringAsync();

                // ... Display the result.
                if (result != null &&
                result.Length >= 50)
                { …
Run Code Online (Sandbox Code Playgroud)

c# wpf httpclient async-await

2
推荐指数
1
解决办法
3172
查看次数

标签 统计

c# ×2

async-await ×1

connection ×1

httpclient ×1

sockets ×1

tcpclient ×1

wpf ×1