new to VBA...Winsock DataArrival event not getting fired.

  • Thread starter Prabuddha Gupta
  • Start date
P

Prabuddha Gupta

I am trying to communicate between java and Excel. in Excel, How and
where should I put my Winsock code so that once excel is up..java
client can communicate. I wrote the following code in a VB form
mudule..it worked fine, but when I copied it in excel userform...its
events are not being fired. it starts fine and and is in listening
mode...java socket send the data fine (doesn't complain about
connection), but dataArrival event is not fired..what could be the
reason..I tried declaring with withevents too.

Thanks for any help..

Prabuddha
*********************************Code*************************

Private Winsock1 As New Winsock

Private Sub cmdSend_Click()
' send data from the excel
Winsock1.SendData "hi from Excel" & vbCrLf
DoEvents
End Sub

Public Sub Main()
' set up the socket to listen on port 10101
Winsock1.LocalPort = 10101
Winsock1.Listen
DoEvents
End Sub

Public Sub Winsock_ConnectionRequest(ByVal RequestID As Long)
' reset the socket, and accept the new connection
Winsock1.Close
Winsock1.Accept RequestID
End Sub

Public Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Winsock1.GetData strData
MsgBox strData
End Sub
 
O

Ophir

Try to use the WithEvents statment on your Winsock var.
If this does not work, try to put a Winsock control on the form and
then use it's events. This might solve your problem.

Ophir
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top