kerryjiang / WebSocket4Net

A popular .NET WebSocket Client
Apache License 2.0
764 stars 273 forks source link

Visual Basic 2015 implementation. #109

Open bottasergio opened 6 years ago

bottasergio commented 6 years ago

Could you please help me with this implementation of WebSocket4Net.

myWebsocket = New WebSocket4Net.WebSocket("wss://lorem.ipsum.com:8734/someServer")
AddHandler myWebsocket.Opened, AddressOf Me.websocket_Opened
AddHandler myWebsocket.Error, AddressOf Me.websocket_Error
AddHandler myWebsocket.Closed, AddressOf Me.websocket_Closed
AddHandler myWebsocket.MessageReceived, AddressOf Me.websocket_MessageReceived
myWebsocket.Open()
Private Sub websocket_Opened(ByVal sender As Object, ByVal e As EventArgs)
    myWebsocket.Send("LOREM;{usuer};{pass}")
End Sub
Private Sub websocket_Error(ByVal sender As Object, ByVal e As SuperSocket.ClientEngine.ErrorEventArgs)
    EventLog1.WriteEntry([String].Format("myWebsocket socketError: {0}", e.Exception), EventLogEntryType.Error, eventID)
End Sub
Private Sub websocket_MessageReceived(ByVal sender As Object, ByVal e As WebSocket4Net.MessageReceivedEventArgs)
    EventLog1.WriteEntry([String].Format("myWebsocket socketMessage: {0}", e.Message), EventLogEntryType.Information, eventID)
End Sub
Private Sub websocket_Closed(ByVal sender As Object, ByVal e As EventArgs)
    EventLog1.WriteEntry([String].Format("myWebsocket websocket_Closed: {0}", e), EventLogEntryType.Information, eventID)
End Sub

I receive this error:

socketError: System.Net.Sockets.SocketException (0x80004005): No se puede ejecutar la operación en un socket ya que el sistema no tiene suficiente espacio de búfer o porque una cola estaba llena

Maybe I need to close connection after I send the message??

Thanks

kerryjiang commented 6 years ago

Could you translate the error message to English?

bottasergio commented 6 years ago

@kerryjiang it means:

An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full

kerryjiang commented 6 years ago

Do you have a lots of concurrent connections? There might be connection leak issue.

bottasergio commented 6 years ago

Yes. I have lot of records that I have to send to my provider via websocket.

bottasergio commented 6 years ago

Is it necessary to close the connection after websocket_MessageReceived or websocket_Error ?

bottasergio commented 6 years ago

@kerryjiang is this a correct use of your component?? if I have a lot of simultaneous calls:

For .... 
  Dim wsDGSA As WebSocket4Net.WebSocket
  wsDGSA = New WebSocket4Net.WebSocket(URL_WSS)
  AddHandler wsDGSA.Opened, AddressOf Me.wsDGSA_Opened
  AddHandler wsDGSA.Error, AddressOf Me.wsDGSA_Error
  AddHandler wsDGSA.Closed, AddressOf Me.wsDGSA_Closed
  AddHandler wsDGSA.MessageReceived, AddressOf Me.wsDGSA_MensajeRecibido
  wsDGSA.Open()
Next

How can I send different data each time?

Thanks for your help.

kerryjiang commented 6 years ago

Can you just use only one connection to send data?

bottasergio commented 6 years ago

No, it is not possible because the server where I have to send data, can only receive one transaction at a time. And I have each 10 seconds, 12 or 15 records to send. Any suggestion?

bottasergio commented 6 years ago

Solved, thanks!

Dim wsDGSA As WebSocket4Net.WebSocket
wsDGSA = New WebSocket4Net.WebSocket(URL_WSS)
AddHandler wsDGSA.Opened, AddressOf Me.wsDGSA_Opened
AddHandler wsDGSA.Error, AddressOf Me.wsDGSA_Error
AddHandler wsDGSA.Closed, AddressOf Me.wsDGSA_Closed
AddHandler wsDGSA.MessageReceived, AddressOf Me.wsDGSA_MensajeRecibido
wsDGSA.Open()
For ...
   wsDGSA.Send(...)
Next
wsDGSA.Close()
wsDGSA.Dispose()