Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 974
  • Last Modified:

MS WinSock Control and receive-buffer...

Hi!

I'm doing a VB 5.0 app. in wich I'm using a MS WinSock Control. I send queries to an Socket server, wich in its place chew on some data, and send them in a pre-designed format back to me. This is not any problem for my Socket client as long as the record I receive is less than 8192 bytes long (8k).

However, if it is, the tcpClient.DataArrival event stops after getting this amount, and I have to put in a "DoEvents" to get the rest of the record. The problem that arrises when I do this, is that I no longer can check wich recordtype the second "shipment" of data is, as it's the second part of a record.

Could this be a problem on the server-side, or can I somehow alter the receive-buffer? (I don't use any API-calls for my TCP/IP sessions).

On the server-side there is an C-application, running on an Dec Alpha-machine, and the send-buffer seems to be set to 15000 bytes. (The largest record I have is 14828 bytes).
The guys that has implemented this says they send the whole buffer in one go, so I should be getting 14828 bytes.

Does anyone have a clue what could be wrong, and maybe a hint on how to fix it?

WR
O.E. Auran
0
oddau
Asked:
oddau
  • 2
1 Solution
 
anthonycCommented:
I would recommend placing an ending character, or sequence of characters, that won't appear in your data stream (chr(1) is a good choice), and continue to read until you get there.  I built a little app, that sends to itself, so you can see this:

Option Explicit
Dim strReceive As String
Dim boolStillReading As Boolean
Dim strHold As String
Private Sub Form_Click()
    Winsock2.SendData String(14828, "A") & Chr(1)
End Sub

Private Sub Form_Load()
    Load Winsock1(1)
    Winsock1(0).LocalPort = 2323
    Winsock1(0).Listen
    Winsock2.Connect "206.152.171.110", "2323"
    DoEvents
End Sub

Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    DoEvents
    Winsock1(1).Accept requestID
End Sub

Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    Dim strTemp As String
   
    Winsock1(1).GetData strTemp, vbString
    MsgBox Len(strTemp)
    strReceive = strReceive & strTemp
   
    If boolStillReading Then
        If InStr(strTemp, Chr(1)) > 0 Then
            boolStillReading = False
        End If
        strHold = strReceive
    End If
           
End Sub
0
 
mrmickCommented:
hmmm... anthonyc, that method would place a limitation on the data that could be sent i.e. you couldn’t perform a generic transfer of data that could contain any combination of characters because you’re "sequence of characters" or marker would interrupt the receive.  It also requires that you search each new block of data (can add up) and it would trash the first part of the next send when two sends were sent close together.

oddau, the problem is that regardless of how large or small a block of data is, it is sent in packets that have a limited size.  The data is reconstructed, buffered and passed to your client app in chunks of varying sizes (whatever size the winsock control chooses - can be as small as a few bytes).

The method I use to receive blocks is to begin each transfer with a info header (which you're already doing - contains the recordtype) and include in the header a long integer which specifies how many total bytes make up the transfer.  This will provide you with a means of separating the current transfer with subsequent transfers, you won’t have to search for a "marker" and it is independent of the data being sent meaning that this method would work for any combination of bytes.

If you would like a code example exploiting this method, I’ll be happy to give you one.  Just send me a note and I’ll reply: mick@owen.wa.com

0
 
anthonycCommented:
the method I provided works fine.  No matter how correct an answer is, Mrmick always has a problem with it.  Are we that point hungry?  I think so.  
0
 
oddauAuthor Commented:
Hi, and thanks for the answer!

As it turned out, I didn't have to use this solution after all. I just do a "While less than 14828 bytes received Then DoEvents", and disable further send(data) until the condition is true.

Anyway, the efforts made are appreciated, and should there be any problems with my solution, I'll switch to AnthonyC's, or MrMick's.

Points go to AnthonyC for his quick response this time.

WR
Odd-Egil

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now