Basic Chat - Making a basic chat

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > VB Programming

Basic Chat - Making a basic chat

warlordluke
Hi all
This is how you make a basic Client/Server Chat

(Server Side)
For this code you require
- 2 Textboxes (You can call them anything you want but i'm going to call them txthst (Chat history) txtmsg (Chat Message))
- 1 Command Button (You can call it what ever you want but i'm going call it cmdsnd (To Send Messages))
- 1 Winsock Control (You can call it what ever you want but i'm going to call it ws (To listen))
MainFrm.frm

Menu
- Exit

CODE

Private Sub Form_Load()
    ws.LocalPort = 12345
    ws.Listen
End Sub

Private Sub Winsock_ConnectionRequest(ByVal RequestID As Long)
   ws.Close
   ws.Accept RequestID
End Sub

Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)

Dim strData As String
   
   ws.GetData strData
   txthst.Text = txthst.Text & vbCrLf & strData
   txthst.SelStart = Len(txthst.Text)
End Sub

Private Sub cmdsnd_Click()
   Winsock.SendData txtChat.Text
   DoEvents
   
   txthst.Text = txthst.Text & vbCrLf & txtmsg.Text
   txtmsg.Text = ""
End Sub


(Client Side)
For this code you require
- 2 Textboxes (You can call them anything you want but i'm going to call them txthst (Chat history) txtmsg (Chat Message))
- 1 Command Button (You can call it what ever you want but i'm going call it cmdsnd (To Send Messages))
- 1 Winsock Control (You can call it what ever you want but i'm going to call it ws (To Connect to the server))

CODE


Private Sub Form_Load()
   
   ws.RemoteHost = "127.0.0.1"
   ws.RemotePort = 12345
   ws.Connect
End Sub

Private Sub cmdSend_Click()

   ws.SendData txtmsg.Text
   DoEvents
   txthst.Text = txthst.Text & vbCrLf & txtmsg.Text
   txtmsg.Text = ""
End Sub

Private Sub Winsock_Connect()

   MsgBox "Connected"
End Sub

Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
   
   ws.GetData strData
   
   txthst.Text = txtmsg.Text & vbCrLf & strData
   
   txthst.SelStart = Len(txthst.Text)
End Sub

Private Sub Winsock_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)
 
   MsgBox "Error: " & Description

End Sub


There you go people and entier tutorial on a basic person to person chat system using winsock and you can expand on this in many different ways. Example adding images to show the different states of the winsock control. (I may show this later) biggrin.gif

 

 

 


Reply

wow
You wouldnt have the server side code for the old vp chat client would you?....lol
Also would this code you posted could it be applyed to my trap17 account?

Reply

JpOlDeRmAn
Nice i tried here right now and it's working but i have a router so nobody can chat with me on my server sad.gif

Reply

Galahad
QUOTE(JpOlDeRmAn @ Jul 29 2006, 04:31 PM) *

Nice i tried here right now and it's working but i have a router so nobody can chat with me on my server sad.gif


You need to configure your router, to forward all incoming data on certain port, to port that your chat server is using for incoming connectios... I think that should do the trick... All have your router forward all the ports to your computer, so all requests would be processed on your computer...

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : chat making chat

  1. Making A Rss Reader - (8)
    is it possible to make a rss reader in vb? im thinking about making one in vb6...
  2. My Guidewriter - Simple Visual Basic program to aid in making guides (3)
  3. Making My About Box Show When I Go ["help --> About"] - giving myself rightful credits (5)
    I've just finished downloading Visual Basic 2005 Express Edition and I love it.
    I've improvised upon their beginners tutorial about creating a browser except I want to create
    an About Box to go with it. I've done the box itself (it's called
    AboutBox1) I just need the code to display it when you click Help --> About . So
    far I've got: CODE Private Sub AboutToolStripMenuItem_Click(ByVal sender As
    System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click          '
    N...



Looking for basic, chat, making, basic, chat

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for basic, chat, making, basic, chat

*MORE FROM TRAP17.COM*
advertisement



Basic Chat - Making a basic chat



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE