PDA

Click to See Complete Forum and Search --> : Source Code for a Chat Program


mitoziz
Jan 10th, 2000, 11:35 AM
Hi, I've looked around but can't seem to find any info on this.

Can someone tell me where I can find source code for a chat program? (in VB, of course)

Thanx in advance

venkatraman_r
Jan 10th, 2000, 12:43 PM
This code snippet is for chat client....you need to add two seperate projects for chat server and client.

Private Sub cmdConnect_Click()
With sckClient
.RemoteHost = "localhost"
.RemotePort = 32000
.Connect
End With
End Sub

Private Sub cmdSend_Click()
If Len(txtMsg.Text) Then
sckClient.SendData txtMsg.Text
End If
End Sub

Private Sub sckClient_DataArrival(ByVal bytesTotal As Long)
Dim sTemp As String
sckClient.GetData sTemp, vbString, bytesTotal
txtHistory.Text = txtHistory.Text & sTemp & vbCrLf
End Sub

------------------------------

code for chat server
------------------------------

Private Sub cmdSend_Click()
If Len(txtMsg.Text) Then
sckServer.SendData txtMsg.Text
End If
End Sub

Private Sub Form_Load()
With sckServer
.LocalPort = 32000
.Listen
End With
End Sub

Private Sub sckServer_ConnectionRequest(ByVal requestID As Long)
With sckServer
If .State <> sckClosed Then
.Close
.Accept requestID
End If
End With
End Sub

Private Sub sckServer_DataArrival(ByVal bytesTotal As Long)
Dim sTemp As String
sckServer.GetData sTemp, vbString, bytesTotal
txtHistory.Text = txtHistory.Text & sTemp & vbCrLf
End Sub

------------------------------------

All you need to do is in the remote host specify the ip address of the client machine..you need to run the program in the client machine too..if u need to try it in the same machine..just copy it as it is..

Good Luck.

Regards,

Venkat :) :)

------------------
venkatraman_r@hotmail.com
ICQ: 45714766
http://venkat.iscool.net

Fox
Jan 10th, 2000, 02:15 PM
If you did install the VB Books Online there's a nice example and everything's explained...

------------------
Fox
gigotz@gmx.net
[No homepage yet]