LAN chat compilation-Problems

Source: Internet
Author: User

I am working on LAN chat software over the past few days. I want to learn how to write winform. But I have encountered a problem and I don't know how to solve it. Please refer to the following for details. Please help me solve the problem:

 

1. This error will pop up after running:

 

2. After clicking OK, the following exception is prompted:

 

3. I found through one-step debugging:

My IPaddress address = iphostentry. Addresslist [0]; the first element of Addresslist [0] is used, but the exact IP address of my computer should be Addresslist [2].

However, I have also tested it on other computers. The exact IP addresses they run include Addresslist [1], Addresslist [3], and Addresslist [5]. I did it, please help me solve this problem.

 

4. My source code is as follows:

     
/// <Summary> /// process the received information and process the file and common messages respectively. /// </Summary> private void merge enews () {try {// initialize accept socket: addressing scheme, socketreceive = new socket (addressfamily. interNetwork, sockettype. stream, protocoltype. TCP); // obtain the local IP address and set the port string hostname = DNS for receiving information. gethostname (); iphostentry = DNS. gethostentry (hostname); IPaddress address = iphostentry. addresslist [0]; ipreceive = new ipendpoint (address, 8001); // bind the local IP address and accept port to the accept socket socketreceive. BIND (ipreceive); // listening port, and set the listening cache size to 1024 byte socketreceive. listen (1024);} catch (exception ERR) {MessageBox. show (err. message);} // defines the buffer byte [] buff = new byte [1024] When receiving information; // continuously accepts the information sent by the client while (true) {// define a chat socket to accept information socket chat = socketreceive. accept (); // defines the chatsession cs = new chatsession (chat, this. lvwdisplayuser); // defines a new thread to receive information sent by other hosts thread newthread = new thread (New threadstart (CS. startchat); newthread. setapartmentstate (apartmentstate. sta); // start the new thread newthread. start ();}}
 
 
Please give me more advice.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.