Instructables

How to make a simple chat program in visual basic using the Microsoft Winsock Control

Picture of How to make a simple chat program in visual basic using the Microsoft Winsock Control
In this instuctable i will show you how to make a simple chat program in visual basic. i will go over what all the code does so you will be learning as you make it, and at the end i will show you how to use it.
 
Remove these adsRemove these ads by Signing Up

Step 2: Creating the user infrence

Now it is time to create the user form

you will need to add the winsock control to the toolbox
do this by:
1. right click somewhere in the toolbox where there is nothing
2. click Components
3. in the long list find Microsoft Winsock Control 6.0 and check the box next to it
4. then click apply then close

Add:
5 text boxes
4 command buttons
1 winsock control

arrange them to look like the second picture below

Step 3: Renaming and other property changes

Picture of Renaming and other property changes
we are now going to be changing the captions(what is says in the command buttons)

1. click command1
2. look on the right side in the properties and find Caption
3. change it to Host

do the same for the rest but make them:

command2 = Connect

command3 = Close

command4 = Send

now we are going to change what the text boxes say

1. click on the text box that says text1
2. go to the properties window and find the Text property
3. make it blank
4. do the same for the one that says Text2
5. now click text3 and change the text property to 127.0.0.1
6. now click text4 and change the text property to 1234
7. now click text5 and change the text property to Name

127.0.0.1 is your local ip so you can test the program on your computer when its done
1234 is the port you can make it whatever you want but just leave it 1234 for now
1-40 of 233Next »
ankita084 months ago

this is working very well in the same pc and thanx a lot for that but i've tried to make it work on two but was not able to do so. can you plz tell me the way how to do it?

fidnah8 months ago
hi
i have error 40020
invalid operation
Chiranjith1 year ago
can u plz let me know how to transfer files instead of text... please... it will b helpful for my project..
twenglish1 (author) 1 year ago
I haven't been on here for a while, so sorry i haven't gotten a chance to reply to a lot of you asking questions or having problems, the way i wrote this chat program i believe it only works with the older vb 6.0 the newer versions do not have the winsock control module, i am not sure how to use it either, i know its possible though
enashton1 year ago
I can seem to find the "Microsoft WinSock" in Visual Basic 2012, please resond with a way to find it.

thank you
every thing should be done but finally have a runtime error as "object required 424"
its good but runtime error "object required" 424
its good but error object required
I tried your code and it works fine so thank you for it.

I want to perform following task in your program :-
1)Group chat
2)Add smilies
3)Sending files

Please note that i don't want to make more changes

I use richtextbox in my program.

I request you to upload pdf to perform above task
Screamz3321 year ago
I am still having trouble with the sckMain.GetData(Data, vbString) line, do you have any suggestions. I fixed the rest of the errors myself, but have no clue with this one.
mukeshdube1 year ago
when i click host and then connect runtime error 40020 occurrs how i can overcome this problem
adandoy1 year ago
thank you now i already know it...
t asdi1 year ago
when i click host and then connect runtime error 40020 occurrs how i can overcome this problem
t asdi1 year ago
when i click host and then connect runtime error 40020 occurrs how i can overcome this problem
thank you
rnvenkat2 years ago
operator '&' is not defined for types 'string' and 'system.windows.forms.textbox'

i am facing this problem in vb.net 2008

pls help me
purni21922 years ago
For the send command we get wrong protocol or connection state for the requested transaction,n for other commands v get a runtime error-424 object required..and no 2 forms appear here;pls help me in this...
i can't download the tut pdf!!
Corliansa2 years ago
there is this word in front = "Run-Time Error '40006';
Corliansa2 years ago
I can't when i click "Send" button it give this message = "Wrong Protocol Or Connection State For The Requested Transaction Or Request" can you fix it?
markjeggar2 years ago
A simple VB.NET chat program with source code

http://vb.net-informations.com/communications/vb.net_chat_server_program.htm

jeggr.
kumali2 years ago
is it working with at least 3 computers?
de7ox5 years ago
Hi, i am coding in VB2008, it worked so far but this part doesn't work @ all for me :

sckMain.state <> sckClose


sckMain.accept requestid


Please e-mail me with a solution asap as i really like this proggy u made!
de7ox@hotmail.com
Thanks!
jflores-3 de7ox3 years ago
I created a chat program without winsock and its works
the correct code is:If sckMain.CtlState <> 0 Then

sckMain.Accept(e.requestID)
how is it possible can you explain
twenglish1 (author)  jflores-33 years ago
How did you do it?
gurgle528 de7ox3 years ago
Dim proCedure As String
sckMain.Close()
sckMain.Accept(e.requestID)
sckMain.Accept(e.requestID)
proCedure = txtLog.Text & "Connected to: " & sckMain.RemoteHostIP & vbCrLf
proCedure = txtLog.Text
you will need to fix the lines, but this is what I have.
Winsock1.Close() Winsock1.Accept(e.requestID)
twenglish1 (author)  de7ox5 years ago
i don't know how to get this program to work with VB2008 you need to make changes to the code, sorry
MunRa2 years ago
How to make the message sent to ListBox if use ENTER BUTTON on Keyboard?

Like chat aplication generally, example: Facebook chat.

Thanks
pradysathi2 years ago
Hai I tried to connect the chat(program which is developed in vb 6) with another system on the LAN. i am finding it hard to do so.kindly help me.
Sir ,
Error "40020" how come ?"
plese reply ..
:D
hyker694 years ago
mr twenglish when i run the program RUN TIME ERROR Occurs and says it Requires an Object how can i fix that?..pls reply until tommorow because im rushing our project tnx..pls teach me how to fix that problem..tnx again..

Successfull.. tnx
twenglish1 (author)  hyker694 years ago
you need to make sure you renamed all the objects correctly
embivert2 years ago
Hi,
I'm paras. I've never tried to run the above program but the way of describing the example is awesome.
I have run-time error "40020" invalid operation at current state
mhimebaugh2 years ago
Operator "&" is not defined for types "String" and "System.Windows.Forms.Textbox"
This message will appear when entering the code for cmdSend. This is the exact code I typed in
Private Sub cmdSend_Click()
sckMain.SendData("[" & txtName.Text & "]" & txtSend.Text)
txtLog = txtLog.Text & "[" & txtName & "]" & txtSend.Text & vbCrLf
txtSend.Text = ""
End Sub
Wait Nevermind i used a diffrent code it works now :P
1-40 of 233Next »