Jump to content

Recommended Posts

Posted

i will show you how to make a program to chating

we need visual basic 6

and mswinsck.ocx

First make a new project

Then add component mswinsck.ocx

and add it on form

now make 2 textbox,2 labels,3buttons(for now) look at image:

yl8lmo69dq2k84gt72n7.jpg

now lets write some codes

open command1 = connect button and write:

Winsock1.Close

Winsock1.RemoteHost = Text1.Text

Winsock1.RemotePort = Text2.Text

Winsock1.Connect

If Winsock1.RemoteHost = Empty Then Winsock1.Close: MsgBox "Add Host Or Ip", vbCritical, "Error"

If Winsock1.RemotePort = Empty Then Winsock1.Close: MsgBox "Add Por", vbCritical, "Error"

ok now lets write on command2 = dis button

winsock1.close

and on command3=Exit buttond jus type

end

After this lets add One more button

command5=LocalHost/Ip

in this button type

msgbox winsock1.LocalHostName & "@ " & winsock1.LocalIP

this is show what is the host and ip names

After this lets Make one command more

command6=Chat

now maybe its more complicated

dont write nothing in this command

add a second form in the same project i think u know how to do it

rename it as Chat or write in the main form form2.caption="Chat"

now lets go back to form1 and open the last button6

in this button type

Form2.show

ok now lets work on Form2

width=640 height=480http://www.imageshack.gr/files/61i2k6ybq7cpdccjbq6a.jpg[/img]

now lets make one biGGG textBox

after thiss add 3 new Buttons like this:

width=640 height=480http://www.imageshack.gr/files/dbtsmdmz508h3mjs5cpe.jpg[/img]

now open button1=send on form2!

write

Form1.Winsock1.SendData Text1

now open Button2=Clear text

and write

text1=clear

and at Button3=Exit

type

form2.hide

(OFC u can add multiline on text1 and scrollbars to make it looks better

like this :

width=640 height=480http://www.imageshack.gr/files/sx1ziek6kg41kkvn995q.jpg[/img]

now we need to type in form2

Private Sub form1_winsock1_dataarrival()

Dim Othchat As String

form1.winsock1.getdata(Othchat)

text1=winsock1.remotehostname & " " & Othchat

End Sub

now i think we are ok with client...

lets make A server now :)

now make a new project with Server caption

add 3 buttons again for now

dont forget to add winsock osx again

anyway

type this in form

Private Sub winsock1_ConnectionRequest(ByVal requestID As Long)

If winsock1.State <> winsock1Closed Then winsock1.Close

winsock1.Accept (requestID)

End Sub

 

button1=listen,button2=close,button3=exit

lets write on button1

setRemoteport=inputbox("Set Port:","")

winsock1.close

winsock1.localport =setRemoteport

winsock1.listen

 

for command2

winsock1.close

 

and command3

end

now lets make one more button

command4=ShowPort

msgbox winsock1.LocalPort,vbInformation,""

and add one more button like button5=Chat

command5

form2.show 'we need again one second Form'

Now Lets work on form 2 again

now add text box like the client and 3 buttons like the client

and dont forget to type again

private sub form1_winsock1_dataarrival()

dim inComeChat as string

form1.winsock1.getdata(inComeChat)

text1=winsock1.remotehostname & " " & inComeChat

Good Luck

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...