Microsoft KB Archive/240747

= BUG: Winsock DataArrival Event Fires Multiple Times =

Article ID: 240747

Article Last Modified on 10/22/2002

-

APPLIES TO


 * Microsoft eMbedded Visual Basic 3.0

-



This article was previously published under Q240747



SYMPTOMS
When you send a string of data to an eMbedded Visual Basic (eVB) Winsock control, the DataArrival event fires twice. For example, if the string is "This is a string," the DataArrival event may fire two times as "T" and "his is a string."



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Create a new Standard EXE project in Visual Basic. Form1 is created by default. Add a TextBox control, a CommandButton control, and a Winsock control to Form1.  Paste the following code into the code window of Form1: Option Explicit Private Sub command1_Click Winsock1.Protocol = 0 Winsock1.Listen MsgBox "Port=" & Winsock1.LocalPort & "LocalIP=" & Winsock1.LocalIP End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long) If Winsock1.State <> 0 Then Winsock1.Close Winsock1.Accept requestID End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long) Dim data As String Winsock1.GetData data, vbString, bytesTotal MsgBox "DataArrival event fired! Bytes Received: " & bytesTotal Text1.Text = Text1.Text & data End Sub  Save the Visual Basic project. Start a new eVB project. Form1 is created by default. Add three TextBox controls, two CommandButton controls, and one Winsock control to Form1.</li>  Paste the following code into the code window of Form1: Option Explicit Private Sub Command1_Click WinSock1.LocalPort = 0 WinSock1.Protocol = 0 WinSock1.RemotePort = Text2.Text WinSock1.RemoteHost = Text1.Text WinSock1.Connect End Sub

Private Sub Command2_Click WinSock1.SendData Text3.Text End Sub </li> Save and run the eVB project.</li> Click Command1 on the Visual Basic project to obtain the Visual Basic Winsock Local Port and Local IP values. Copy and paste these values into TextBox1 and TextBox2 on the eVB project to configure the eVB Winsock Remote Port and Remote Host. Click Command1 to connect.</li> In Textbox3, type This is a string, and click Command2 to send the data to the Visual Basic project. Notice that the DataArrival event fires twice.</li></ol>

Keywords: kbbug kbfix kbtoolkit KB240747

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.