小编Jac*_*ker的帖子

设置TCP/IP客户端和服务器以通过网络进行通信

我正在尝试学习一些关于套接字编程的知识,我偶然发现了TcpListener和TcpClient,因为我读到它们对于初学者来说稍微容易一些.我想要完成的基本要点是拥有一个小型表格,可以在我的笔记本电脑和同一网络上的另一台笔记本电脑上运行,并让他们能够进行通信,即相互发送一串文字.有了这个,我希望能进一步发展:)

到目前为止,我已经使用msdn和互联网上的各种指南创建了客户端和服务器程序.我可以让他们在一台笔记本电脑上运行时进行通信,但是当我将客户端移动到另一台笔记本电脑时,我无处可去.我认为我的主要问题是我不太了解客户端如何找到服务器IP,因为我认为我可以对其进行硬编码,但是当我再次回来时,我确信IP会发生变化.有没有办法让两者以更动态的方式连接以包含不断变化的IP?我目前的客户代码:

    public void msg(string mesg)
    {
        lstProgress.Items.Add(">> " + mesg);
    }

    private void btnConnect_Click(object sender, EventArgs e)
    {
        string message = "Test";
        try
        {
            // Create a TcpClient.
            // Note, for this client to work you need to have a TcpServer 
            // connected to the same address as specified by the server, port
            // combination.
            Int32 port = 1333;
            TcpClient client = new TcpClient(<not sure>, port); //Unsure of IP to use.

            // Translate the passed message into ASCII and …
Run Code Online (Sandbox Code Playgroud)

.net c# tcp client-server winforms

7
推荐指数
1
解决办法
1万
查看次数

将数据从HTML表中获取到数据表中

好的,我需要查询实时网站以从表中获取数据,将此HTML表放入DataTable然后使用此数据.到目前为止,我已经设法使用Html Agility Pack和XPath来获取我需要的表中的每一行,但我知道必须有一种方法可以将其解析为DataTable.(C#)我目前使用的代码是:

string htmlCode = "";
using (WebClient client = new WebClient())
{
htmlCode = client.DownloadString("http://www.website.com");
}
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();

doc.LoadHtml(htmlCode);

//My attempt at LINQ to solve the issue (not sure where to go from here)
var myTable = doc.DocumentNode
.Descendants("table")
.Where(t =>t.Attributes["summary"].Value == "Table One")
.FirstOrDefault();

//Finds all the odd rows (which are the ones I actually need but would prefer a
//DataTable containing all the rows!
foreach (HtmlNode cell in doc.DocumentNode.SelectNodes("//tr[@class='odd']/td"))
{
string test = …
Run Code Online (Sandbox Code Playgroud)

html c# linq xpath html-agility-pack

5
推荐指数
2
解决办法
6万
查看次数

标签 统计

c# ×2

.net ×1

client-server ×1

html ×1

html-agility-pack ×1

linq ×1

tcp ×1

winforms ×1

xpath ×1