FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


how to create a simple chat using winsock in visual basic???





dainty_nellie
please help me,.,.i really don't know how to use winsock,,.,.my group and i were assigned to create a chat program using winsock,.,.,.,,,whether it is simple or not,but the simpler the better.,.,.please help me.....i don't know how to start,i don't even understand how to use winsock in visual basic?!!!!!!!
Helios_155
winsock is very very simple.

firstly load the winsock control (goto add components and its called "microsoft winsock control 6.0")

then on your form create 3 text boxes. label them as such: txtRemoteIP, txtMain, txtMessage

txtmain should have these settings:
MultiLine should be set to true
scrollbars should be set to vertical
enabled should be set to false

then create 2 buttons and call them cmdSend and cmdConnect

then put a winsock control in and call it sckMain

then open up the code and put in this

Code:
 Private Sub cmdConnect_Click()
With sckMain
.RemoteHost = txtRemoteIP.Text
.RemotePort = "6677"
.Connect
End With
End Sub

Private Sub cmdSend_Click()
If sckMain.State = sckClosed Then: Exit Sub
sckMain.SendData txtMessage.Text
End Sub

Private Sub Form_Load()
sckMain.LocalPort = "6677"
sckMain.Listen
End Sub

Private Sub sckMain_Close()
txtMain.Text = txtMain.Text & vbCrLf & "<Session Ended>"
sckMain.LocalPort = "6677"
sckMain.Listen
End Sub

Private Sub sckMain_Connect()
txtMain.Text = txtMain.Text & vbCrLf & "<Connected with: " & sckMain.RemoteHostIP & ">"
End Sub

Private Sub sckMain_ConnectionRequest(ByVal requestID As Long)
If MsgBox("would you like to connect with " & sckMain.RemoteHostIP & "?", vbYesNo) = vbYes Then
' you must close the socket before you can accept it
    sckMain.Close
    sckMain.Accept requestID
End If
End Sub

Private Sub sckMain_DataArrival(ByVal bytesTotal As Long)
Dim buffer As String
sckMain.GetData (buffer)
MsgBox buffer
txtMain.Text = txtMain.Text & vbCrLf & "Them: " & buffer
End Sub

Private Sub sckMain_SendComplete()
txtMain.Text = txtMain.Text & vbCrLf & "You: " & txtMessage.Text
txtMessage.Text = ""
End Sub


there may be some errors in it but that was a rough chat program i made up in the last 10 mins for you.

however looking at the date of your post i relise this may be of no use to you. well anyway feel free to edit this code as you want and if anybody can see any errors please tell me so i can correct them.
dainty_nellie
Thank you for your help. Very Happy
Related topics
MS Visual Basic Studio 2005 Express Edition
Visual Basic Build Problem
how to create chat program using winsock???????????????
how to use winsock in visual basic????????
Visual Basic Tutorial - Control Arrays: What, Why and How
Visual Basic RUles
Freelance Programmer
Visual Basic Tutorial - File I/O in VB: Text Files
GD and Visual Basic... Is it possible?
ms access and visual basic
VB Help for those who need small pointers in Visual Basic
How to code a simple blog using PHP
Visual Basic 6 vs Visual Basic 2010
Visual basic 6
Reply to topic    Frihost Forum Index -> Computers -> Software

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.