Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VB Client/Server chat and queuing/stacking messages

Posted on 2003-11-09
3
250 Views
Last Modified: 2010-05-01
Hi there,

I'm busy writing a client/server chat application in VB6 (I know re-inventing the wheel here but I want to see how far I can get with this without having to use third-party components, apps, etc.).

I've got the basics working pretty well - one application is acting as the server (accepting, sending and relaying messages between client applications. These messages can be normal messages between users or various commands sent by the client/server (refresh user list, change nickname, connect, disconnect, etc).

As I said all works pretty well - I can see when users are connected, send and receive messages. But only if there's a few connected clients and only if not more than one message comes into the server or client application at the same time.

What I'm interested in the best way to implement some sort of messaging queue or stack for the messages (received and sent) so that the client/server application can parse and process each message separately and not bomb-out/ignore messages that contain more than one command in them.

I hope my question is clear enough - let me know if you need more information.

Thanks in advance.

Regards,
CyberSoft

PS: I will check/respond as and when I get a chance over the next 2 days - afte that I'm on vacation for a few days (till Sunday) so I won't be able to respond immediately to comments/posts.
0
Comment
Question by:CyberSoft
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 9711097
Just add some kind of end of message marker to your messages.  Many people use vbCrLF.

Then, whenever your client/server receives data, just add whatever it may be to the end of a string buffer.

Next, check your string buffer for the presence of a vbCrLf using the InStr function.  If there is one, then extract the first command from the buffer using the Left command up to the marker and reset the buffer to whatever is left after the marker.  Do this in a loop and you will process all (if any) commands you receive.

I don't know how you communicating between your client/server so here is some generic code that can be modified easily:

Private Sub whatEverEventTriggersWhenYouReceiveData()
    Static bufferData As String
    Dim markerposition As Integer
    Dim currentMessage As String
   
    bufferData = bufferData & whatEverFunctionYouUseToGetBufferData()
    Do
        markerPos = InStr(bufferData, vbCrLf)
        If markerPos > 0 Then ' Found a marker
            ' Extract complete message from buffer
            currentMessage = Left$(bufferData, markerPos - 1) ' leave off vbCrLf

            'now do something with that message
            yourMessageProcessingSub currentMessage
   
            ' Reset buffer to what's after the marker
            bufferData = Mid$(bufferData, markerPos + 2) ' leaves out vbCrLf
        End If
    Loop While markerPos > 0 ' go back and process all complete messages in buffer
End Sub

Regards,

Idle_Mind
0
 
LVL 3

Author Comment

by:CyberSoft
ID: 9723714
Hi Idle_Mind,

Sorry for the delay in getting back to you. You are absolutely right. I don't know why I wasn't thinking simpler - I was thinking more along the lines of arrays and timers and pushing messages into an array ... blah blah blah.

When the simple answer was right there (I've even used it elsewhere in my app to split separate parts of a message, eg: message and userid and recipientid)

Well you came up with a solution that works so the points are yours well done.

Regards,
CyberSoft
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9725135
Glad I could help.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question