HelpPort and Chat in Visual Basic

Posts 1–8 of 8 · Page 1 of 1
Port and Chat in Visual Basic

Can any one give me the codes for them ?
I have Winsock Control 6
Please give me codes for VB [2008] or [2010]
----------------------------------------------------
Making your own chat program!!!
----------------------------------------------------

This tutorial will teach you how to make your very own chat program.

What you will need:
Winsock Control (Winsock) (Project->Components->MS Winsock Control 6.0)
3 Command Buttons (cmdSend,cmdConnect,cmdListen)
2 Text Boxes (txtConnect,txtSend)
1 ListBox (lstShow)
You may add more (Labels and Such) to make it look better if you wish, Im making it simple

First off Place your buttons on the form in any position you wish. txtConnect will be used to Get the IP address to connect to. lstShow will be used to display sent messages. txtSend will be used to type the messages. Same purposes with command buttons. cmdListen will be used to listen for connections. After you have placed everything in logical positions, we can begin the coding. Lets start with the listening procedure.

Code:
Private Sub cmdListen_Click()
'Setup the local port to connect to. You can put any port number.
Winsock.LocalPort = 4545
'Listen for incoming connections
Winsock.Listen
End Sub
When the cmdListen button is clicked, the winsock will listen for incoming connections on port 4545. You may put any post number but rarely used ones are best so useless information doesnt get intercepted by the winsock. Now lets see what happens when a user connections on a listening winsock.
Code:
Private Sub Winsock_ConnectionRequest(ByVal requestID As Long)
'Close a connection incase a previous one was opened.
Winsock.Close
'Accept the request
Winsock.Accept requestID
'If connection is made, Tell user
If Winsock.State = sckConnected Then
lstShow.AddItem "Connection Made"
Else
msgbox "No Connection Made",,"Error"
End If	
End Sub
That procedure accepts a connection when one is requested. Only one connection may be present per winsock. Now lets setup the connection procedures.
Code:
Private Sub cmdConnect_Click()
Dim IP as Integer
'Get the Computer to connect to
IP = txtConnect.text
'Close Previous Connection
Winsock.Close
'Connect to Computer Using the IP and Port (Port must be the same as the Listening Winsock)
Winsock.Connect IP, 4545
'If connection is made, Tell user
If Winsock.State = sckConnected Then
lstShow.AddItem "Connection Made"
Else
msgbox "No Connection Made",,"Error"
End If	
End Sub
This procedure executes when a person clicks the connect command button. It then get the IP address typed into txtConnect and Setups a connection to a Listening Winsock using the IP and a Local Port. It is very important that the Local Port is the same as the Local Port on the listening winsock. Otherwise the Connection will not work and an error will come up. Notice that I do not include error handlers in any procedures. This is because im trying to make thins Basic and Short. If you want go smooth code. It would be benifical to include error handlers. Now lets get the the heart of the program. Sending and Displaying messages. Lets start with sending.
Code:
Private Sub cmdSend_Click()
Dim Data as String
'Get the data to send
Data = txtSend.text
'Append your hostname so they know who sent it
Data = Winsock.LocalHost & ": " & Data
'Send your data
Winsock.SendData Data
'Display the Data for yourself
lstShow.AddItem Data
End Sub
This procedure sends the message typed into txtSend. Notice that is no connection is present an error will occur. Again, Im just trying to make the code simple. Onto the last part of the program, Recieveing Data.
Code:
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim Data as String
'Get the data sent to the winsock and put it in the Variable "Data"
Winsock.GetData Data
'Display the data
lstShow.AddItem Data
End Sub
Quote Originally Posted by tynab View Post
----------------------------------------------------
Making your own chat program!!!
----------------------------------------------------

This tutorial will teach you how to make your very own chat program.

What you will need:
Winsock Control (Winsock) (Project->Components->MS Winsock Control 6.0)
3 Command Buttons (cmdSend,cmdConnect,cmdListen)
2 Text Boxes (txtConnect,txtSend)
1 ListBox (lstShow)
You may add more (Labels and Such) to make it look better if you wish, Im making it simple

First off Place your buttons on the form in any position you wish. txtConnect will be used to Get the IP address to connect to. lstShow will be used to display sent messages. txtSend will be used to type the messages. Same purposes with command buttons. cmdListen will be used to listen for connections. After you have placed everything in logical positions, we can begin the coding. Lets start with the listening procedure.

Code:
Private Sub cmdListen_Click()
'Setup the local port to connect to. You can put any port number.
Winsock.LocalPort = 4545
'Listen for incoming connections
Winsock.Listen
End Sub
When the cmdListen button is clicked, the winsock will listen for incoming connections on port 4545. You may put any post number but rarely used ones are best so useless information doesnt get intercepted by the winsock. Now lets see what happens when a user connections on a listening winsock.
Code:
Private Sub Winsock_ConnectionRequest(ByVal requestID As Long)
'Close a connection incase a previous one was opened.
Winsock.Close
'Accept the request
Winsock.Accept requestID
'If connection is made, Tell user
If Winsock.State = sckConnected Then
lstShow.AddItem "Connection Made"
Else
msgbox "No Connection Made",,"Error"
End If	
End Sub
That procedure accepts a connection when one is requested. Only one connection may be present per winsock. Now lets setup the connection procedures.
Code:
Private Sub cmdConnect_Click()
Dim IP as Integer
'Get the Computer to connect to
IP = txtConnect.text
'Close Previous Connection
Winsock.Close
'Connect to Computer Using the IP and Port (Port must be the same as the Listening Winsock)
Winsock.Connect IP, 4545
'If connection is made, Tell user
If Winsock.State = sckConnected Then
lstShow.AddItem "Connection Made"
Else
msgbox "No Connection Made",,"Error"
End If	
End Sub
This procedure executes when a person clicks the connect command button. It then get the IP address typed into txtConnect and Setups a connection to a Listening Winsock using the IP and a Local Port. It is very important that the Local Port is the same as the Local Port on the listening winsock. Otherwise the Connection will not work and an error will come up. Notice that I do not include error handlers in any procedures. This is because im trying to make thins Basic and Short. If you want go smooth code. It would be benifical to include error handlers. Now lets get the the heart of the program. Sending and Displaying messages. Lets start with sending.
Code:
Private Sub cmdSend_Click()
Dim Data as String
'Get the data to send
Data = txtSend.text
'Append your hostname so they know who sent it
Data = Winsock.LocalHost & ": " & Data
'Send your data
Winsock.SendData Data
'Display the Data for yourself
lstShow.AddItem Data
End Sub
This procedure sends the message typed into txtSend. Notice that is no connection is present an error will occur. Again, Im just trying to make the code simple. Onto the last part of the program, Recieveing Data.
Code:
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim Data as String
'Get the data sent to the winsock and put it in the Variable "Data"
Winsock.GetData Data
'Display the data
lstShow.AddItem Data
End Sub
Read my thread again
Please give me codes for VB [2008] or [2010]
Quote Originally Posted by -[Exorcist]- View Post

Read my thread again
try googe'ling
@tynab, Thanks for taking time to make post. -- glad to see someone else calling them "command buttons" still : )

@OP which part of that looked like vb6 to you? ...and why are you insisting on using the Winsock control? you might as well be using vb6...
Quote Originally Posted by abuckau907 View Post
@tynab, Thanks for taking time to make post. -- glad to see someone else calling them "command buttons" still : )

@OP which part of that looked like vb6 to you? ...and why are you insisting on using the Winsock control? you might as well be using vb6...
So, where's the codes for make it in VB 10 ?
I found it, but where do I put it?
Quote Originally Posted by abuckau907 View Post
I found it, but where do I put it?
Here, with [ code] [/code]
Posts 1–8 of 8 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us