简单的聊天程序

页面导航:首页 > 软件编程 > vb.net > 简单的聊天程序

简单的聊天程序

来源: 作者: 时间:2016-02-05 12:32 【

聊天程序NOTE: This program requires mswinsck.ocxAssumes: There are alot of things to set up in order for this code to work correctly. Here are the

 

 

聊天程序

 

NOTE: This program requires mswinsck.ocx

 

Assumes:

 There are alot of things to set up in order for this code to work correctly. Here are the complete list of things you will need to do:

 

1. Add the mswinsck.ocx to your project

 

2. Create a textbox and name it txtHost This will be the box where the remote host is entered

 

3. Create a textbox and name it txtLocalP.This will be the box where the local port is entered

 

4. Create a textbox and name it txtRemotePThis will be the box where the remote port is entered

 

5. Create a textbox and name it txtNick This will be the box you will enter your nickname (aka screenname)

 

6. Create a textbox and name it txtSend This will be the box you type in to send stuff to the chatroom

 

7. Create a large textbox and name it txtMainThis will be the chatroom

 

8. Make txtMain multiline and also add vertical scrollbars

 

9. Create a command button and name it cmdC. Give it the caption ";Connect";

 

10. Create a command button and name it cmdD. Give it the caption ";Disconnect";

 

11. Create a command button and name it cmdSend. Give it the caption ";Send";. This will be the button that sends the text in txtSend to the chatroom.

 

12. Put a winsock control on the form and name it sckSend

 

13. Labels can be put so you can remember which text box is which. Also, it would be best to erase all the text in the text boxes (ie: Get rid of Text1 written in the box)

 

 

 When 2 people have the program running, this is how you connect:

 

1. First, enter a nickname in the txtNick box. This is the name that will come before what you say in the chatroom.

 

2. In the txtHost textbox, you must put the other persons IP address or hostname.

 

3. You and the other person must both think up any number to be your local port (Just make sure theyre different numbers. ie: My local port is 1000, my friends local port is 2000)

 

4. After youve both made up your local host and entered it in the txtLocalP textbox, you must next enter the other persons local port in your txtRemoteP textbox. For example, My local port is 1000. and my remote port is 2000... My friends local port would be 2000 and my friendss remote port would be 1000.

 

5. Both of you must now click the connect button.

 

6. Now just type text in the txtSend textbox and click the ";Send"; button. You will notice the text moved into the chatroom. This text is visible by both people! Congratulations!

 

 

Side Effects:None

 

 Code provided by Planet Source Code(tm) (http://www.PlanetSourceCode.com) as is, without warranties as to performance, fitness, merchantability,and any other warranty (whether expressed or implied).

—————————————————————————————————————————————————————————————

 

 

 

Private Sub cmdC_Click()

 

  If Len(txtNick) < 1 Then make sure there is a nickname entered

    MsgBox ";You must enter a nickname first!";

    txtNick.SetFocus put the cursor in the nickname textbox

    Exit Sub

  End If

 

  If Len(txtHost) < 1 Or Len(txtLocalP) < 1 Or Len(txtRemoteP) < 1 Then

    MsgBox ";Please make sure a Host, a Local Port, and a Remote Port have been entered!";

    Exit Sub

  End If

 

  sckSend.RemoteHost = txtHost set the host

  sckSend.LocalPort = txtLocalP set the local port

Tags:

相关文章

    文章评论

    
    <