Click here to Skip to main content
15,905,420 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Did Charset.Auto use a unicode or ansi string version of the dll? Pin
Dave Kreskowiak19-Oct-08 5:42
mveDave Kreskowiak19-Oct-08 5:42 
QuestionVB.NET Pin
onlyehtisham18-Oct-08 7:23
onlyehtisham18-Oct-08 7:23 
AnswerRe: VB.NET PinPopular
Paul Conrad18-Oct-08 7:41
professionalPaul Conrad18-Oct-08 7:41 
GeneralRe: VB.NET Pin
onlyehtisham18-Oct-08 7:46
onlyehtisham18-Oct-08 7:46 
GeneralRe: VB.NET PinPopular
Paul Conrad18-Oct-08 7:48
professionalPaul Conrad18-Oct-08 7:48 
GeneralRe: VB.NET Pin
csciwizard18-Oct-08 8:39
csciwizard18-Oct-08 8:39 
GeneralRe: VB.NET Pin
Paul Conrad18-Oct-08 8:42
professionalPaul Conrad18-Oct-08 8:42 
QuestionUDP Async Send Receive Timeout Issues Pin
ozoid18-Oct-08 4:05
ozoid18-Oct-08 4:05 
I am confused with the UDP Socket when used with an Async call - The code works ok - as long as the client is online - if the client is offline - i end up with many unclosed sockets.
I am running the code repeatedly to many different clients for polling SNMP devices.
For some reason the first time the code is run and hits an offline client - an object disposed exception occurs. each successive call just leaves an open socket when hitting an offline client. all other times - as long as the client is online the sockets are closed neatly.
ultimately this code needs to run repeatedly non-stop to poll many devices 100+


<code>Public Class UDPStateObject
Public Endpoint As IPEndPoint
Public buffer(1024) As Byte ' Receive buffer.
Public udpSocket As Socket = Nothing
End Class

Public Sub SendSNMP(ByVal request As SNMPRequest)
Dim sobj As New UDPStateObject
Dim UDPServ As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
Dim ipAdd As IPAddress = IPAddress.Parse(request.IPAddress)
Dim remoteEP As New IPEndPoint(ipAdd, 161)
Dim packet As Byte() = buildPacket(request)
Try
sobj.udpSocket = UDPServ
sobj.Endpoint = remoteEP
Dim localEP As New IPEndPoint(IPAddress.Any, 0)
sobj.udpSocket.Bind(localEP)
sobj.udpSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 4000)
sobj.udpSocket.SendTimeout = 4000
sobj.udpSocket.BeginSendTo(packet, 0, packet.Length, SocketFlags.None, remoteEP, New AsyncCallback(AddressOf PacketSent), sobj)
Dim sresult As Boolean = sendDone.WaitOne(4000, False)
If Not sresult Then
utils.WriteErrorLogEntry("SNMPTx Timeout")
Else
'-----------------------------------------------------------------------------------
Dim ipe As New IPEndPoint(remoteEP.Address, localEP.Port)
sobj.udpSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 8000)
sobj.udpSocket.ReceiveTimeout = 8000
sobj.udpSocket.BeginReceiveFrom(sobj.buffer, 0, 1024, SocketFlags.None, ipe, New AsyncCallback(AddressOf ReceivePacket), sobj)
Dim rresult As Boolean = receiveDone.WaitOne(8000, False)
If Not rresult Then
utils.WriteErrorLogEntry("SNMPRx Timeout")
If sobj.udpSocket.IsBound Then
utils.WriteErrorLogEntry("SNMP IsBound")
sobj.udpSocket.Close()
End If
End If
'-----------------------------------------------------------------------------------
End If
Catch ex As SocketException
RaiseEvent onError(ex.ToString, "Send SNMP Error", request.IPAddress)
End Try
End Sub
Public Sub PacketSent(ByVal ar As IAsyncResult)
Try
Dim srv As UDPStateObject = CType(ar.AsyncState, UDPStateObject)
Dim bytesSent As Integer
Try
bytesSent = srv.udpSocket.EndSend(ar)
Catch ode As ObjectDisposedException
RaiseEvent onError("SNMPTx Sent - Socket Disposed " & ode.Message, "No Socket", srv.Endpoint.Address.ToString)
Exit Sub
End Try
sendDone.Set()
If bytesSent > 0 Then
'ok
Else
srv.udpSocket.Close()
End If
Catch ex As SocketException
RaiseEvent onError(ex.ToString, "Packet Sent SNMP Error:" & ex.ToString, "")
End Try
End Sub
Sub ReceivePacket(ByVal ar As IAsyncResult)
Dim ipstr() As String = {"", ""}
Dim client As UDPStateObject = CType(ar.AsyncState, UDPStateObject)
Dim BytesReceived As Integer = 0
Try
BytesReceived = client.udpSocket.EndReceive(ar)
Catch ode As ObjectDisposedException
RaiseEvent onError("SNMPRx Receive - Socket Disposed " & ode.Message, "No Socket", ipstr(0))
Exit Sub
End Try
receiveDone.Set()
Dim snsa As SocketAddress = client.Endpoint.Serialize
Dim ipe As New IPEndPoint(IPAddress.Any, 1000)
Dim ep As EndPoint = ipe.Create(snsa)
ipstr = ep.ToString.Split(":")
If BytesReceived > 0 Then
Dim x As Byte() = client.buffer
Dim resp As SNMPResponse = decodePacket(x, ipstr(0))
RaiseEvent UDPDataRx(resp, ipstr(0))
Else
RaiseEvent onError("SNMPRx Receive Packet - Empty Buffer", "No Client", ipstr(0))
End If
End Sub</code>
QuestionWindows forms and Console window problem. Pin
LloydA11118-Oct-08 3:49
LloydA11118-Oct-08 3:49 
AnswerRe: Windows forms and Console window problem. Pin
Dave Kreskowiak18-Oct-08 5:37
mveDave Kreskowiak18-Oct-08 5:37 
GeneralRe: Windows forms and Console window problem. Pin
LloydA11124-Oct-08 14:01
LloydA11124-Oct-08 14:01 
QuestionIs it possible to send mail uisng TCPClient Class in VB.net Pin
Dharmchand Dhingra18-Oct-08 1:33
Dharmchand Dhingra18-Oct-08 1:33 
AnswerRe: Is it possible to send mail uisng TCPClient Class in VB.net Pin
Dave Kreskowiak18-Oct-08 3:31
mveDave Kreskowiak18-Oct-08 3:31 
GeneralRe: Is it possible to send mail uisng TCPClient Class in VB.net Pin
Dharmchand Dhingra18-Oct-08 4:39
Dharmchand Dhingra18-Oct-08 4:39 
GeneralRe: Is it possible to send mail uisng TCPClient Class in VB.net Pin
Dave Kreskowiak18-Oct-08 5:34
mveDave Kreskowiak18-Oct-08 5:34 
Questionneed a code Pin
saeedtack18-Oct-08 0:15
saeedtack18-Oct-08 0:15 
AnswerRe: need a code Pin
Guffa18-Oct-08 1:25
Guffa18-Oct-08 1:25 
AnswerRe: need a code - troll baiting Pin
Mycroft Holmes18-Oct-08 3:05
professionalMycroft Holmes18-Oct-08 3:05 
GeneralRe: need a code - troll baiting Pin
LloydA11118-Oct-08 3:39
LloydA11118-Oct-08 3:39 
GeneralRe: need a code - troll baiting Pin
Guffa18-Oct-08 7:00
Guffa18-Oct-08 7:00 
AnswerRe: need a code Pin
Dave Kreskowiak18-Oct-08 3:30
mveDave Kreskowiak18-Oct-08 3:30 
GeneralRe: need a code Pin
Paul Conrad18-Oct-08 6:20
professionalPaul Conrad18-Oct-08 6:20 
QuestionRequest for Permission of Type System.Data.OleDb.OleDbPermission in vb.net Pin
vijaylumar17-Oct-08 21:47
vijaylumar17-Oct-08 21:47 
AnswerRe: Request for Permission of Type System.Data.OleDb.OleDbPermission in vb.net Pin
Mycroft Holmes17-Oct-08 23:07
professionalMycroft Holmes17-Oct-08 23:07 
AnswerRe: Request for Permission of Type System.Data.OleDb.OleDbPermission in vb.net Pin
Vimalsoft(Pty) Ltd17-Oct-08 23:14
professionalVimalsoft(Pty) Ltd17-Oct-08 23:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.