Solved

Winsock Control - Control array DataArrival event

Posted on 1997-09-17
4
1,199 Views
Last Modified: 2013-11-13
Hi,
  I'm trying to create a simple server application that will accept incoming data from a client application.  I'm trying to do what the examples say to do on pp 174-176 of the VB Components Tool Guide (using the Winsock Control).  I need to be able to accept more than 1 connection request at a time, so I'm trying to create a control array as follows...

Private intMax As Long

Private Sub Form_Load()
    intMax = 0
    tcpServer(0).LocalPort = 2345
    tcpServer(0).Listen
End Sub

Private Sub tcpServer_ConnectionRequest _
(Index As Integer, ByVal requestID As Long)
    If Index = 0 Then
        intMax = intMax + 1
        Load tcpServer(intMax)
        tcpServer(intMax).LocalPort = 0
        tcpServer(intMax).Accept requestID
        Load txtData(intMax)
    End If
End Sub

...so far so good.  I've followed instructions by setting the index property of tcpServer to 0 which supposedly creates the array.  I also did likewise with txtData.  I'm not sure if txtData is supposed to display the incoming data from the client, but I'm assuming it is.  The instructions don't say.
Now I complete the scenario by including the event procedure for the arrival of the data...

Private Sub tcpServer(intMax)_DataArrival(ByVal bytesTotal As Long)
    ' Declare a variable for the incoming data.
    ' Invoke the GetData method and set the Text
    ' property of a TextBox named txtOutput to
    ' the data.
    Dim strData As String
    tcpServer(intMax).GetData strData
    txtData(intMax).Text = strData
End Sub

...and I get a compiler error saying that the underscore in the procedure declaration is an invalid character.  ((inMax)_DataArrival).  If this is invalid then why is it not also invalid in scalar context...

Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long)   ???

...If I leave out the (intMax), I get an error that states that the Procedure declaration does not match the description of event or procedure having the same name.  How should I handle this?
0
Comment
Question by:zingbust
  • 4
4 Comments
 
LVL 5

Accepted Solution

by:
volking earned 100 total points
ID: 1435288
You've got a syntax error ...
Try ...

Private Sub tcpServer_DataArrival (Index as Integer, ByVal bytesTotal As Long)

Which incident of tcpServer is passed as a parameter Index.
In your example, "Index as integer" is replacing "intMax".

===========> Frederick Volking
0
 
LVL 5

Expert Comment

by:volking
ID: 1435289
I'd rewrite your sub like this ...

Private Sub tcpServer_DataArrival(Index as integer, ByVal bytesTotal As Long)
      ' Declare a variable for the incoming data.
      ' Invoke the GetData method and set the Text
      ' property of a TextBox named txtOutput to
      ' the data.
      Dim strData As String
      tcpServer(index).GetData strData
      txtData(index).Text = strData
End Sub
0
 
LVL 5

Expert Comment

by:volking
ID: 1435290
Or even like this ...

Private Sub tcpServer_DataArrival(Index as integer, ByVal bytesTotal As Long)
      tcpServer(index).GetData txtData(index).Text
End Sub
0
 
LVL 5

Expert Comment

by:volking
ID: 1435291
I might also suggest caution in handling the results in txtData(index).Text the actual string you get returned may be suffixed with garbage which happens to be left in the recieve buffer so I'd improve the above like this to safeguard:

Private Sub tcpServer_DataArrival(Index as integer, ByVal bytesTotal As Long)
      tcpServer(index).GetData txtData(index).Text
      txtData(index).Text = left$(txtData(index).Text, bytesTotal)
End Sub

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA: Select SQL query based on a config Sheet v2 11 52
Re-position the objects 7 126
Fastest way to find and count same items VB6 16 48
Java pass by reference 3 25
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

730 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