How I can get the amount of bytes that had been sent via winsock through TCP connection?
2 Answers
0
votes
It's simply the return value of send(). For more information about send or Winsock in general look here: http://msdn.microsoft.com/library/windows/desktop/ms740149%28v=vs.85%29.aspx
0
votes
Question:
- Do you want to know how many bytes were sent with a single .SendData() call?
- Or do you want to know how many bytes were sent throughout the lifetime of your program running?
Question 1.
Several options:
You can just calculate the length of the data you're sending. It's very easy if it's a string: Len(DataBeingSent) will give you the number of bytes. Tell us what you're sending or show us some code.
You can keep track using a form-scope variable, but this is a pretty poor way to do it in my opinion unless it is for question #2 above.
Option Explicit Private lonBytesSent As Long Private Sub Winsock1_Connect() Dim strData As String strData = "This example uses a string but will work with any type being sent." ' Reset the number of bytes sent from any previous packets. lonBytesSent = 0 Winsock1.SendData strData End Sub Private Sub Winsock1_SendComplete() MsgBox CStr(lonBytesSent) & " byte(s) sent on last transmission.", vbInformation End Sub Private Sub Winsock1_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long) lonBytesSent = lonBytesSent + bytesSent End Sub
Question 2.
If this is the case, the above code will work just remove the lonBytesSent = 0
before the .SendData()
call. You may want to use a bigger data type than a Long
if you will be sending a lot of data.