socket class raise event  
Author Message
JuKiM





PostPosted: .NET Framework Networking and Communication, socket class raise event Top

Hello, I've defined an asynchronous socket class.. But what I'm finding now, is that the delegate that executes when arrives some data from the socket isn't raised. I don't know if I'm explaining.

I have this:


Public Function ConectSocket() As Boolean
Dim answer As Boolean
On Error GoTo Err1
answer = True
Dim Addr As IPAddress = _
Dns.GetHostEntry("127.0.0.1").AddressList(0)
If Not Addr Is Nothing Then
Dim EP As New IPEndPoint(Addr, 2028)
Clientsocket = New Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Clientsocket.BeginConnect(EP, AddressOf ConnectCallback, Nothing)
End If

ContErr1:
ConectSocket = answer
Exit Function
Err1:
answer= False
Resume ContErr1
End Function


Public Sub ConnectCallback(ByVal ar As IAsyncResult)
On Error GoTo err1
Clientsocket.EndConnect(ar)

Dim dlg As New NoParamsDelegate(AddressOf ConnectedUI)
Me.Invoke(dlg)
dlg.Invoke()

Dim bytes(4095) As Byte
Clientsocket.BeginReceive(bytes, 0, bytes.Length, SocketFlags.None, _
AddressOf ReceiveCallBack, bytes)
err1:
End Sub


Public Delegate Sub NoParamsDelegate()


Public Sub ConnectedUI()
'The code to execute when connects
End Sub

But when I do Me.Invoke(dlg), is gives me an error.. How can i do it

Thanks!



.NET Development21  
 
 
RizwanSharp





PostPosted: .NET Framework Networking and Communication, socket class raise event Top

Public Sub ConnectCallback(ByVal ar As IAsyncResult)
On Error GoTo err1

Clientsocket.EndConnect(ar)

Dim dlg As

If(Me.InvokeRequired) Then // its a Cross Thread...

Me.Invoke( New NoParamsDelegate(AddressOf ConnectedUI)) ' Isn't it Enough

Else

ConnectedUI()

End If
Dim bytes(4095) As Byte
Clientsocket.BeginReceive(bytes, 0, bytes.Length, SocketFlags.None, _
AddressOf ReceiveCallBack, bytes)
err1:
End Sub

I think It should work

I dont see purpose if this dlg.Invoke()

I'm C# developer I'm sorry if i'm wrong somewhere!

Best Regards,