Solved

MS WinSock Control and receive-buffer...

Posted on 1998-03-03
4
955 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

630 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