Jump to content
xisto Community
Sign in to follow this  
warlordluke

Basic Chat Making a basic chat

Recommended Posts

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

Private Sub Form_Load()     ws.LocalPort = 12345     ws.ListenEnd SubPrivate Sub Winsock_ConnectionRequest(ByVal RequestID As Long)    ws.Close    ws.Accept RequestIDEnd SubPrivate 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 SubPrivate 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))

Private Sub Form_Load()        ws.RemoteHost = "127.0.0.1"    ws.RemotePort = 12345    ws.ConnectEnd SubPrivate Sub cmdSend_Click()    ws.SendData txtmsg.Text    DoEvents    txthst.Text = txthst.Text & vbCrLf & txtmsg.Text    txtmsg.Text = ""End SubPrivate Sub Winsock_Connect()    MsgBox "Connected"End SubPrivate 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 SubPrivate 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: " & DescriptionEnd 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) :P

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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


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...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.