Solved

VB Client/Server chat and queuing/stacking messages

Posted on 2003-11-09
3
256 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 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 86

Expert Comment

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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

707 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