Solved

MS WinSock Control and receive-buffer...

Posted on 1998-03-03
4
946 Views
Last Modified: 2013-11-13
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
Comment
Question by:oddau
[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
4 Comments
 
LVL 6

Accepted Solution

by:
anthonyc earned 200 total points
ID: 1458374
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
 
LVL 8

Expert Comment

by:mrmick
ID: 1458375
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
 
LVL 6

Expert Comment

by:anthonyc
ID: 1458376
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
 
LVL 1

Author Comment

by:oddau
ID: 1458377
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The viewer will learn how to implement Singleton Design Pattern in Java.
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…

751 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