[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VB Client/Server chat and queuing/stacking messages

Posted on 2003-11-09
3
Medium Priority
?
261 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
[X]
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
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 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 86

Expert Comment

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 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