Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Communiqué

Post new topic   Reply to topic
LAN CHAT
View previous topic :: View next topic  
Author Message
diwa_sen
Newbie


Joined: 25 Jul 2005
Posts: 1

PostPosted: Jul 25th, 2005 05:38 AM    Post subject: LAN CHAT Reply with quote

Hello!!

Please help me in develope a LAN CHAT Application. I need to know how to find the computers connected in a network using WINSOCK.
Back to top
View user's profile Send private message Send e-mail
vbman995
Moderator


Joined: 19 Aug 2005
Posts: 264
Location: Planet Earth

PostPosted: Aug 21st, 2005 07:51 AM    Post subject: Reply with quote

Check out planet-source-code.com. They have a lot of source code about Chat programs. You could learn how to make a LAN Chat program from one of the source code programs.
Back to top
View user's profile Send private message
ASoufan
Regular


Joined: 15 Aug 2005
Posts: 56
Location: Jordan

PostPosted: Sep 4th, 2005 09:56 AM    Post subject: Reply with quote

hello, you need client and server, server to host and accept client connection and distrebute data through sockets, I will show you simple thing

1- Server Part:
Code:
Private Sub Command1_Click()
'now we want to send some data to the server..
'to do that we must use the senddata sub of winsock
If Text1 = "" Then Exit Sub
w1.SendData Text1  'this will send the data that we wrote in Text1 textbox
DoEvents
List1.AddItem "Client : " & Text1 'we add what we said to the list
Text1.Text = "" 'after we send the data we clear the textbox
End Sub
Private Sub Command2_Click()
On Error Resume Next
w1.Close
w1.LocalPort = 188
w1.Listen
'this will close the connection with the client and open the port to wait for another connection
End Sub

Private Sub Form_Load()
w1.LocalPort = 188 'with this we set the port we want to use for the connection
w1.Listen 'this command opens the port and waits (listens) for a connection
End Sub
Private Sub w1_Close()
'this sub raizes when our winsock close ( when we disconnect form the client)
List1.AddItem "Disconnected"
End Sub
Private Sub w1_ConnectionRequest(ByVal requestID As Long)
'this event is called when a client request a connection with the server
If w1.State <> sckClosed Then w1.Close
w1.Accept requestID
'with this commands i wrote above..we accept the connection request to the server..
'now we are connected with the client
List1.AddItem "Connected"
End Sub
Private Sub w1_DataArrival(ByVal bytesTotal As Long)
'when the Client sends any data this event raises
Dim dat As String
w1.GetData dat ' with this command the data are
                'being stored in the dat variable so
                'we can use them
List1.AddItem "Client : " & dat 'this will add the data we received from the client to the list box (adding a "client : " in front of the string to know where this came from :o)
End Sub
Private Sub w1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
'in case of any errors
'this event raises and the number and description hold the info of the error
MsgBox "Error : " & Description
End Sub




2- Client Part
Code:
Private Sub Command1_Click()
On Error Resume Next
'now we want to send some data to the server..
'to do that we must use the senddata sub of winsock
If Text1 = "" Then Exit Sub
w1.SendData Text1  'this will send the data that we wrote in Text1 textbox
DoEvents
List1.AddItem "Client : " & Text1 'we add what we said to the list
Text1.Text = "" 'after we send the data we clear the textbox
End Sub

Private Sub Command2_Click()
On Error GoTo t
a = InputBox("Enter The Ip Or Hostname Of The Server ( eg.127.0.0.1 or George )", "Remote Host", "127.0.0.1")
If a <> "" Then
    w1.Close ' close the winsock in case it was open
    w1.Connect a, "188" 'now a will be our host,so we
                        'request a connection form the host to
                        'connect with him using port 188 (you can change this to whatever you want BUT client and host MUST use the same port )
                        'if the server accept the connection the w1_connect event is raised
    DoEvents
End If
Exit Sub
t:
MsgBox Error
End Sub

Private Sub Form_Load()
MsgBox "Simple Chat Client By George Papadopoulos"
End Sub

Private Sub w1_Close()
'this sub raizes when our winsock close ( when we disconnect form the server)
List1.AddItem "Disconnected"
End Sub

Private Sub w1_Connect()
'there we write what we what our program to do
'when the connection with the host is established
List1.Clear
List1.AddItem "Connected to " & w1.RemoteHostIP 'w1.remotehostip is a function that will return as the hosts ip
End Sub

Private Sub w1_DataArrival(ByVal bytesTotal As Long)
'when the server sends any data this event raises
Dim dat As String
w1.GetData dat ' with this command the data are
                'being stored in the dat variable so
                'we can use them
List1.AddItem "Server : " & dat 'this will add the data we received from the server to the list box (adding a "server : " in front of the string to know where this came from :o)
End Sub

Private Sub w1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
'in case of any errors ( like when the host don't accept your connection request)
'this event raises and the number and description hold the erros info
MsgBox "Error : " & Description
End Sub



This is a very simple client and server using mswinsck.ocx, all u need is buttons and text boxes as shown in the code above, good Luck!

_________________
Ahmed Soufan
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Communiqué All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic