Solved

MS WinSock Control and receive-buffer...

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to implement Singleton Design Pattern in Java.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now