Home > Software engineering >  VB winsock receiving data will slow down
VB winsock receiving data will slow down

Time:09-20

Please help me look at my code? Why receiving data will be more and more slow, I am the first to send a command to my server, the server will then return some warning information, with tens of thousands of lines of information about,
Receive the HTML code is as follows:
 Private Sub Winsock_DataArrival (ByVal bytesTotal As Long) 

The Static strData, strSend As Byte

Winsock. GetData strData, vbString

RichTextBox1. Text=RichTextBox1. Text & amp; StrData

RichTextBox1. SelStart=Len (RichTextBox1. Text)

End Sub

CodePudding user response:

 Private Sub Winsock_DataArrival (ByVal bytesTotal As Long) 
Dim strData () As Byte
Dim f As Integer
ReDim strData (bytesTotal - 1)
Winsock. GetData strData, vbByte
F=FreeFile ()
Open "data" for append as # f
Print # f, StrConv (strData, vbUnicode)
Close # f
'RichTextBox1. Text=RichTextBox1. Text & amp; StrConv (strData, vbUnicode)
'RichTextBox1. SelStart=Len (RichTextBox1. Text)

End Sub

CodePudding user response:

 Winsock. GetData strData, vbArray + vbByte 

CodePudding user response:

Thank you very much, but if I find my way, also can write directly into the TXT file, is there any way can show receive files, but does not affect the speed?

CodePudding user response:

Don't use RichTextBox1, use the listview control

CodePudding user response:

RichTextBox1 refresh is time-consuming

CodePudding user response:

 Private Sub Winsock_DataArrival (ByVal bytesTotal As Long) 
Dim strData () as byte
ReDim strData (bytesTotal - 1)
Winsock. GetData strData, vbbyte
RichTextBox1. Text=RichTextBox1. Text & amp; Strconv (strData, vbUnicode)
RichTextBox1. SelStart=Len (RichTextBox1. Text)
Erase strData
End Sub

Try, slow estimates is should be static variables declared with the static's wrong with you

CodePudding user response:

I think, "are getting slower and slower," the key reason, or is it 1:
RichTextBox1. Text=RichTextBox1. Text & amp; StrData

When the content of the "text" a lot of that "string operation" behind time-consuming increases (secondary factors), to "object assignment" also consumes a lot of time,
And operation of the building Lord "frequent refresh content", will appear more and more slow,

Maybe use qinguangjun123 said method, on the 4th floor can be improved,

CodePudding user response:

It will be better and slow ah, you need to see all the received data? Don't need, truncation, show only the latest article n is ok,

CodePudding user response:

reference bigassangel2010 reply: 3/f
thank you very much, but if I find my way, also can be written into the TXT file directly, is there any way can show receive files, but does not affect the speed?

No matter use which controls, it is suggested that the content placed on variables, after receiving again, according to text attributes assigned to control or interface controls display update accumulation will pull far slow program running speed,

CodePudding user response:

references 9 f zdingyun response:
Quote: reference bigassangel2010 reply: 3/f

Thank you very much, but if I find my way, also can write directly into the TXT file, is there any way can show receive files, but does not affect the speed?

No matter use which controls, it is suggested that the content placed on variables, after receiving again, according to text attributes assigned to control or interface controls display update accumulate much slow programs run at,

According to the latest receiving data, background processing will each receive data written to the file, need to refer to the display and control,

CodePudding user response:

Thank you for your help, I find a way, tried a feasible, share with you,
 
Private Const WM_USER=& amp; H400
Private Const EM_EXSETSEL=(WM_USER + 55)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal HWND As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam) As Long As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal HWND As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Const WM_VSCROLL=& amp; H115
Const SB_BOTTOM=7
Const WM_KEYDOWN=& amp; H100
Const VK_LEFT As Long=& amp; H25

Dim txtlen As Long

Private Sub txtwrite (STR As String)

SendMessage RichTextBox1. The HWND, EM_EXSETSEL, 0, txtlen
RichTextBox1. SelText=STR & amp; VbNewLine
Txtlen=txtlen + LenB (STR) + 2
SendMessage RichTextBox1. The HWND, EM_EXSETSEL, 0, txtlen
PostMessage RichTextBox1. The HWND, WM_KEYDOWN, VK_LEFT, 0
PostMessage RichTextBox1. The HWND, WM_VSCROLL and SB_BOTTOM, 0

End Sub

Private Sub WinsockAHP_DataArrival (ByVal bytesTotal As Long)

The Static strData, strSend As Byte

WinsockAHP. GetData strData, vbString
Txtwrite (strData)

End Sub



Refer to the http://blog.sina.com.cn/s/blog_6379dd3b0100u32n.html

Now I have another question: I received data character some should be turned into two rows in one line, is there a way to solve?

CodePudding user response:

Don't know how many predecessors in the TCP Socket
Send (many) send (less) send (wealth)
Has been so much illness recv (), recv (wealth)
Inside the trap!
http://bbs.csdn.net/topics/380167545
  • Related