|
-
Nov 7th, 2003, 08:30 AM
#1
Thread Starter
Member
Using the system.net.sockets
Hey all, I have a puzzling question I am hoping someone can answer. I have created two apps. A client app and server app. These applications send messages back and forth. When the client sends a message to the server, the server processes the message and then sends the message back to the client. Frequently, mupltiple messages may need to be sent back to the client from the server. The server sucessfully fires off these messages one by one, but they are then stored in the stream and when the client picks up the message, it picks up all of the messages out of the stream and puts them into one long string. I want to figure out how to somehow have the client pickup the message out of the stream process the message, then go back and get the next message out of the stream. Below is the client code which retreives the messages in the stream. Right now if the server sends multiple messages to the client the client will pick up anything the server has sent, not just the first message. Let me know what you think! Thanks in advance.
CLIENT CODE WHICH GETS THE MESSAGE SENT BY THE SERVER
While TransCompleteIn = "" Or TransCompleteIn = "1"
Dim bytes As Int64 = stream.Read(data, 0, data.Length)
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
MsgBox(responseData.Length)
'Call A Parsing Function To Parse Out The Message String
Parser(responseData)
'Call a Message Processing Function to Process the Message
ProcessMsg()
responseData = ""
End While
-
Nov 7th, 2003, 02:13 PM
#2
There are really two approaches to take here:
1: Terminate every message with a special character, like a newline. Read the buffer until you reach this character; parse the results, and then continue until the buffer is empty or until it doesn't end with the special character.
2: Make the first two/four bytes of every message the message length. Read that many bytes from the buffer, parse the message, and then repeat until there are less than that number of bytes in the buffer, or the buffer is empty.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Nov 8th, 2003, 03:30 PM
#3
Addicted Member
not sure, but if you recieve asyn and use >>
bytesreceived = TCPClient.GetStream.EndRead(ar)
i dont think your gonna have any problems
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|