Setting up a TCP/IP Client and Server to communicate over a network

前端 未结 2 643
梦谈多话
梦谈多话 2021-02-06 07:25

I am trying to learn a little about socket programming and I have stumbled across TcpListener and TcpClient to use as I read they are slightly easier for beginners. The basic ji

2条回答
  •  囚心锁ツ
    2021-02-06 07:47

    If you know the name of the computer you want to connect to then you can find its IP quite easily with System.Net.DNS.

    var ip = System.Net.Dns.GetHostEntry("JacksLaptop"); 
    string ipString = ip.AddressList[0].ToString();
    

    The IP you think you're using may not be the one in location 0 of that array so watch out for that.

提交回复
热议问题