Reputation: 783
Basically my server sends a client a string which is then broken down on the client side using Dim data() As String = receivedString.Split("|"c)
an example of a string would be MESSAGE|TestUser|This Is The Message
what i want to do when this string is received is firstly check to see if this user has already sent a message to this client before(should already have a window up with the current 'chat') if the user has sent a message before append the text to say a rich text box. if the user hasn't sent a message before a new instance of 'chat window' is created and then any future messages from the server goes to this instance of the window.
thanks, Houlahan
Dim data() As String = message.Split("|"c)
Select Case data(0)
Case "MESSAGE"
Try
If conversations.ContainsKey(data(1)) Then
Dim convoWindow As ChatWindow
convoWindow = conversations.Item(data(1))
convoWindow.RichTextBox1.AppendText(data(2))
Else
conversations.Add(data(1), New ChatWindow())
Dim convoWindow As ChatWindow
convoWindow = conversations.Item(data(1))
convoWindow.Show()
convoWindow.RichTextBox1.AppendText(data(2))
End If
Upvotes: 0
Views: 234
Reputation: 32258
You could accomplish this in a slew of ways. The first that pops into my head would be to create a Dictionary object that associates your TestUser
as the key in association with a Form
that represents a conversation. e.g.
conversations.Add(testUser, new FormConversation(...))
When a message is received, you would reference the dictionary that kept track of all your ongoing conversations.
If no key exists with the user name, create a new form and add the user to the dictionary along with a reference to the form. If one does exist, which can be extracted from the dictionary based on the user name, simply bring that one to the front and pass the message to it.
Upvotes: 1