Winsock using vb to accept data often receive less the first byte, seek a solution
CodePudding user response:
Code?
Is not when you're dealing with an array with the wrong subscript,
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
CodePudding user response:
reference 1st floor Tiger_Zhao response: code? Is not when you're dealing with an array with the wrong subscript, Not wrong, only occasionally appear correct packet CodePudding user response:
reference stt192020 reply: 3/f not wrong, only occasionally appear correct packet You do not have the right to subcontract receiving data, the previous process is much more a byte, Or do you remove the input buffer, the part of the data is discarded, CodePudding user response:
reference 4 floor Tiger_Zhao response: [Quote=reference stt192020 reply: 3/f] not wrong, only occasionally appear correct packet You do not have the right to subcontract receiving data, the previous process is much more a byte, Or do you remove the input buffer, the part of the data is discarded, No, when I was on the same computer for data transmission will not lose data, but use the hair will be lost when the first number, and it is often lost, but there are also normal CodePudding user response:
Private Sub sckclient1_DataArrival (ByVal bytesTotal As Long) Dim thestring As String Dim strdata () As Byte Dim pos As Integer Sckclient1. GetData strdata (), vbArray Or vbByte For pos=0 To UBound (strdata) Thestring=thestring & amp; "-" & amp; Strdata (pos) & amp; "-" This is my receiving process CodePudding user response:
refer to the second floor zhao4zhong1 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 Didn't see, this is my code Private Sub sckclient1_DataArrival (ByVal bytesTotal As Long) Dim thestring As String Dim strdata () As Byte Dim pos As Integer Sckclient1. GetData strdata (), vbArray Or vbByte For pos=0 To UBound (strdata) Thestring=thestring & amp; "-" & amp; Strdata (pos) & amp; "-" When I use the network debugging assistant debug can be received correctly, so should be received without handle, please give directions CodePudding user response:
How much data? Winsock unless buffer overflow, is generally not easy to lose data, Add some Debug. Print, see bytesTotal, UBound (strdata), thestring is normal, CodePudding user response:
Private Sub sckclient1_DataArrival (ByVal bytesTotal As Long) Dim thestring As String Dim strdata () As Byte Dim pos As Integer ReDim strdata (bytesTotal - 1) Sckclient1. GetData strdata (), vbArray Or vbByte For pos=0 To UBound (strdata) Thestring=thestring & amp; "-" & amp; Strdata (pos) & amp; "-" CodePudding user response:
refer to the eighth floor Tiger_Zhao response: how much data at a time? Winsock unless buffer overflow, is generally not easy to lose data, Add some Debug. Print, see bytesTotal, UBound (strdata), thestring is normal, Four bytes at a time CodePudding user response:
references to the tenth floor stt192020 response: Quote: refer to the eighth floor Tiger_Zhao response: How much data? Winsock unless buffer overflow, is generally not easy to lose data, Add some Debug. Print, see bytesTotal, UBound (strdata), thestring is normal, A 4 bytes Concept error, the Tcp flow, 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 CodePudding user response:
11 references zhao4zhong1 response: concept errors, Tcp is a stream, Ignorance! DataArrival received the parcel and trigger 4 bytes not subcontract again, CodePudding user response:
refer to 12 floor Tiger_Zhao reply: [Quote=11 references zhao4zhong1 response:] concept errors, Tcp is a stream, Ignorance! DataArrival received the parcel and trigger won't subcontract, 4 bytes The sender sends 4 bytes, the receiver may DataArrival 1 + 1 + 1 + 1 2 + 1 + 1 3 + 1 1 + 2 + 1 1 + 1 + 2 1 + 3 2 + 2 3 + 1 4 CodePudding user response:
reference 13 floor zhao4zhong1 reply: sender sends 4 bytes, the receiver may DataArrival 1 + 1 + 1 + 1 2 + 1 + 1 3 + 1 1 + 2 + 1 1 + 1 + 2 1 + 3 2 + 2 3 + 1 4 No, WinSock twice sent only once DataArrival is likely, will not put into 4 bytes multiple packages, WinSock is not a serial port! WinSock is not a serial port! [size=32 px] WinSock is not a serial port! [/size] CodePudding user response:
TCP buffer the default size of 4096 bytes, At a time is split into multiple DataArrival sent because the content just across TCP buffer and at the end of the beginning next time, Perhaps will never be a 1 + 1 + 1 + 1 But 4095 + +... 4094 + +... nullnull