|
-
Feb 1st, 2005, 05:36 AM
#1
Thread Starter
Lively Member
How to LOOP this ?
VB Code:
Public Function receive() As String
Dim stringBuffer As String
Dim recvBuffer1(tcpClient.ReceiveBufferSize) As Byte
Dim recvBuffer2(tcpClient.ReceiveBufferSize) As Byte
Dim recvBuffer3(tcpClient.ReceiveBufferSize) As Byte
Dim recvBuffer4(tcpClient.ReceiveBufferSize) As Byte
Dim recvBuffer5(tcpClient.ReceiveBufferSize) As Byte
ns.Read(recvBuffer1, 0, CInt(tcpClient.ReceiveBufferSize))
stringBuffer = Encoding.ASCII.GetString(recvBuffer, 0, CInt(tcpClient.ReceiveBufferSize))
ns.Read(recvBuffer2, 0, CInt(tcpClient.ReceiveBufferSize))
stringBuffer = stringBuffer + Encoding.ASCII.GetString(recvBuffer2, 0, CInt(tcpClient.ReceiveBufferSize))
ns.Read(recvBuffer3, 0, CInt(tcpClient.ReceiveBufferSize))
stringBuffer = stringBuffer + Encoding.ASCII.GetString(recvBuffer3, 0, CInt(tcpClient.ReceiveBufferSize))
ns.Read(recvBuffer4, 0, CInt(tcpClient.ReceiveBufferSize))
stringBuffer = stringBuffer + Encoding.ASCII.GetString(recvBuffer4, 0, CInt(tcpClient.ReceiveBufferSize))
ns.Read(recvBuffer5, 0, CInt(tcpClient.ReceiveBufferSize))
stringBuffer = stringBuffer + Encoding.ASCII.GetString(recvBuffer5, 0, CInt(tcpClient.ReceiveBufferSize))
Return stringBuffer
End Function
Anyone know how to loop this ? for your information, the number of receive buffer is LOOP depending on the networkstream. If data haven't finish read, it's shall not create another receive buffer. anyone ?
-
Feb 1st, 2005, 05:39 AM
#2
Member
Re: How to LOOP this ?
what do you wand to make ?
-
Feb 1st, 2005, 05:54 AM
#3
PowerPoster
Re: How to LOOP this ?
Hi,
If you are saying you want to handle an unknown number of recvBuffers then try
Dim recvBuffers(0) As Byte
then loop through with a counter starting at 0; adding the byte to recvBuffers(Counter); then increment counter by 1 until no more bytes.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 1st, 2005, 05:57 AM
#4
Thread Starter
Lively Member
Re: How to LOOP this ?
sorry for that, let me explain it.
I would like to append the string(receive in terms of byte array) until the last data from the networkstream comes in. I do this because the amount of data that I receive is very big(picture) and I wish to receive all the byte and converting it back to string without cut off. And after that return it. : ) mind to find out ?
-
Feb 1st, 2005, 05:59 AM
#5
Thread Starter
Lively Member
Re: How to LOOP this ?
 Originally Posted by taxes
Hi,
If you are saying you want to handle an unknown number of recvBuffers then try
Dim recvBuffers(0) As Byte
then loop through with a counter starting at 0; adding the byte to recvBuffers(Counter); then increment counter by 1 until no more bytes.
mind to code it out? I am newbie in vb... thanks..
-
Feb 1st, 2005, 06:00 AM
#6
Re: How to LOOP this ?
You 'd need to change how you declare your arrays...use an array of arrays instead!
VB Code:
Dim recvBuffers(4)() As Byte 'an array of arrays
recvBuffers(0) = New Byte(tcpClient.ReceiveBufferSize) {}
recvBuffers(1) = New Byte(tcpClient.ReceiveBufferSize) {}
recvBuffers(2) = New Byte(tcpClient.ReceiveBufferSize) {}
recvBuffers(3) = New Byte(tcpClient.ReceiveBufferSize) {}
recvBuffers(4) = New Byte(tcpClient.ReceiveBufferSize) {}
For i As Integer = 0 To 4
ns.Read(recvBuffers(i), 0, CInt(tcpClient.ReceiveBufferSize))
stringBuffer = Encoding.ASCII.GetString(recvBuffers(i), 0, CInt(tcpClient.ReceiveBufferSize))
Next i
Let us know how you get on.
I don't live here any more.
-
Feb 1st, 2005, 06:02 AM
#7
Thread Starter
Lively Member
Re: How to LOOP this ?
why am I doing that way? Because I found out that the maximum buffer size for the receivebuffersize is 8192 bytes. My biggest problem is that I can't receive fully from the server so I need to create many receivebuffersize and append the string. I also need to return the data ONLY after it's finish reading the last data from the server. thanks !
-
Feb 1st, 2005, 06:14 AM
#8
Thread Starter
Lively Member
Re: How to LOOP this ?
 Originally Posted by wossname
You 'd need to change how you declare your arrays...use an array of arrays instead!
VB Code:
Dim recvBuffers(4)() As Byte 'an array of arrays
recvBuffers(0) = New Byte(tcpClient.ReceiveBufferSize) {}
recvBuffers(1) = New Byte(tcpClient.ReceiveBufferSize) {}
recvBuffers(2) = New Byte(tcpClient.ReceiveBufferSize) {}
recvBuffers(3) = New Byte(tcpClient.ReceiveBufferSize) {}
recvBuffers(4) = New Byte(tcpClient.ReceiveBufferSize) {}
For i As Integer = 0 To 4
ns.Read(recvBuffers(i), 0, CInt(tcpClient.ReceiveBufferSize))
stringBuffer = Encoding.ASCII.GetString(recvBuffers(i), 0, CInt(tcpClient.ReceiveBufferSize))
Next i
Let us know how you get on. 
No, this doesn't work. The number of recvbuffer created will need to base on how many data to receive. Could you try it for me ? thanks!
-
Feb 1st, 2005, 06:32 AM
#9
PowerPoster
Re: How to LOOP this ?
Hi,
Having had another look at your code why not
Pseudo Code
Public Function receive() As String
Dim stringBuffer As String
Dim recvBuffer1(tcpClient.ReceiveBufferSize) As Byte
Do While (not end of file)
ns.Read(recvBuffer1, 0, CInt(tcpClient.ReceiveBufferSize))
stringBuffer += Encoding.ASCII.GetString(recvBuffer, 0, CInt
(tcpClient.ReceiveBufferSize))
(here clear recvBuffer1 if necessary)
Loop
Return stringBuffer
End Function
Sorry, I'm not familiar with what you are trying to do so I'm not sure about the use of ns.Read, so I've used Pseudo Code.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 1st, 2005, 06:45 AM
#10
Thread Starter
Lively Member
Re: How to LOOP this ?
 Originally Posted by taxes
Hi,
Having had another look at your code why not
Pseudo Code
Public Function receive() As String
Dim stringBuffer As String
Dim recvBuffer1(tcpClient.ReceiveBufferSize) As Byte
Do While (not end of file)
ns.Read(recvBuffer1, 0, CInt(tcpClient.ReceiveBufferSize))
stringBuffer += Encoding.ASCII.GetString(recvBuffer, 0, CInt
(tcpClient.ReceiveBufferSize))
(here clear recvBuffer1 if necessary)
Loop
Return stringBuffer
End Function
Sorry, I'm not familiar with what you are trying to do so I'm not sure about the use of ns.Read, so I've used Pseudo Code.
My problem is mainly base on how to receive fully from the server before it return the data to where it calls.
I know there is a (in my code, 'ns' = networkstream) networkstream.dataAvailable. It seems like much more close to what I suppost to do. The main objective of this receive class is to receive all the data from server before it return. And another problem, the buffer is only 8192byte and it need to create multiple recvBuffer in order to receive all the data.
Just to make it easy to understand:
The data is about 10000 long. If the buffersize is only 100, I need to create 100 recvBuffer and append the data in order. The data is surely need to be fully receive and the number of recvBuffer created is depend on the data.
Thanks for you people who tried it for me, I appreciate it. And I hope I can get what I am need soon. Thanks !
-
Feb 1st, 2005, 06:58 AM
#11
PowerPoster
Re: How to LOOP this ?
Hi,
Are you saying that you don't know how to get data from a file?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Feb 1st, 2005, 07:12 AM
#12
Thread Starter
Lively Member
Re: How to LOOP this ?
 Originally Posted by taxes
Hi,
Are you saying that you don't know how to get data from a file?
No, I don't know how to receive the data until the last data comes in. In short, don't know how to receive fully from server before it return.
I got my code simplified.
VB Code:
Public Function receive() As String
Dim stringBuffer As String
Dim recvBuffers(4)() As Byte 'an array of arrays
|
recvBuffers(0) = New Byte(tcpClient.ReceiveBufferSize) {} |
recvBuffers(1) = New Byte(tcpClient.ReceiveBufferSize) {} |-----> this is the part I am concerntrate on. Which have to decide how many recvBuffers to create
recvBuffers(2) = New Byte(tcpClient.ReceiveBufferSize) {} |
recvBuffers(3) = New Byte(tcpClient.ReceiveBufferSize) {} |
recvBuffers(4) = New Byte(tcpClient.ReceiveBufferSize) {} |
For i As Integer = 0 To 4 Step 1 -------------------->number of loop also depending on how many recvBuffer created
ns.Read(recvBuffers(i), 0, CInt(tcpClient.ReceiveBufferSize))
stringBuffer = stringBuffer + Encoding.ASCII.GetString(recvBuffers(i), 0, CInt(tcpClient.ReceiveBufferSize))
Next
Return stringBuffer
End Function
In case you don't aware, the number of recvBuffer is base on data comes in. If still have data, create another recvbuffer. if no, then exit the loop.
thanks wossname for the code above. Texas...can you fugure out.. ?
-
Feb 1st, 2005, 07:43 AM
#13
PowerPoster
Re: How to LOOP this ?
Hi,
You don't need to use more than one recvBuffers if you are simply going to add it's contents to the string. It's just a question of looping until the end of file marker is received, provided that the maximum length of a string variable is not exceeded, in which case you would use a string array.
My problem is that I am not familiar with handling Byte input as opposed to characters. If no one else chips in with an answer, I will do some testing this afternoon.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
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
|