|
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>
|
|
|
|
|
Hello,
Ive been working on an application that has both a form and console window, I did this by creating a Windows Form Application and then going to the projects properies and changing the "Application Type" property to Console Application, and everything seems to work all right, but Im trying (with no luck ) to get the console window and the form to align up with each other, Ive tried Me.SetDisplayRectLocation(Console.WindowLeft, Console.WindowTop) and many other variations but nothing seems to work, so I was just wondering if anyone has any ideas of how this can be done.
Help greatly appreciated,
Thanks,
Lloyd
Lloyd J. Atkinson
"Logic will get you from A to B, but imagination will take you everywhere" - ALbert Einstein
I look at Microsoft, and turn to my poster on the wall saying: "Bang head here in case of stress".
|
|
|
|
|
Lloyd Atkinson wrote: Ive been working on an application that has both a form and console window
What are you using the console window for?? if you wanted total control of the window, it would probably be easier to just create your own console window and leave the app as a Windows Forms application.
|
|
|
|
|
Well I suppose I could make a form and dress it up like a console window, but I would have to write a fair bit of code to get it to fully work the same as a proper console window
Lloyd J. Atkinson
"Logic will get you from A to B, but imagination will take you everywhere" - ALbert Einstein
I look at Microsoft, and turn to my poster on the wall saying: "Bang head here in case of stress".
|
|
|
|
|
Hi All,
Anyone can tell me, Is it possible to send mail using Socket.TCPClient Class in VB.net.
I am able to send mail using SMTPClient Class and now i m trying to send mail using TCPClient Class.
if anyone know about this problem then please provide me source code.
Thanks
Regards,
Dharmchand Dhingra
|
|
|
|
|
Yes, it's possible, but why would you want to?? You'd have to implement your own SMTP Client class to achieve this.
|
|
|
|
|
yes it is working with SMTP Client class but when proxy is on the server side then it is not working. So i want to try to send mail using TCP Client Class.
Thanks,
Regards,
Dharmchand Dhingra...
|
|
|
|
|
So what are you going to change that's going to make it work?? Without knowing the exact nature and cuase of the problem, how are you going to write code to get around it??
If the proxy is on the server side, there is probably a problem with it's configuration. That proxy needs to be forwarding the data that on the Internet side to the correct port on the server, inside the proxy. If it's not, no amount of code you write is going to get around this problem.
|
|
|
|
|
for connecting two image (cycle and squre )we use component line but I need a code of component line or class for creating logical connecttion bitween them not just a simple line.I meen that shows they are realy connected together. contact me :saeedrobot@yahoo.com
|
|
|
|
|
saeedtack wrote: for connecting two image (cycle and squre )we use component line but I need a code of component line or class for creating logical connecttion bitween them not just a simple line.I meen that shows they are realy connected together.
What are you talking about? In what way would you like to "connect" the images? When you say that you want a "logical connection", what do you expect this connection to accomplish?
saeedtack wrote: contact me :saeedrobot@yahoo.com
You ask in the forum and you get the replies in the forum. If you are too lazy to revisit the forum, do you expect anyone to make an effort to help you? Besides, you can get a notification by mail when anyone replies to your postings.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Troll
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Whats troll baiting?
Lloyd J. Atkinson
"Logic will get you from A to B, but imagination will take you everywhere" - ALbert Einstein
I look at Microsoft, and turn to my poster on the wall saying: "Bang head here in case of stress".
|
|
|
|
|
Trolling[^]
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
saeedtack wrote: need a code
Stop right there. That little phrase automatically get's your post ignored. It shows you haven't put the effort into solving the problem yourself, so why should we put the effort into helping you?? We'll help you with YOUR code, not someone elses.
|
|
|
|
|
Dave Kreskowiak wrote: need a code
Stop right there. That little phrase automatically get's your post ignored. It shows you haven't put the effort into solving the problem yourself, so why should we put the effort into helping you?
Ditto that. You should steer him towards rent-a-coder, he could accept a cheap bid for some crap code, and he could learn the concept of what you pay for is what you get.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
hi
i am trying to run an application from my network. from Adminstrator system I am able to run this perfectly but others (users) cannot run it. I get the error;
Applicaton attempted to perform an operation not allowed by the security policy. To grant this application the require permission, contact your systems administrator, or use the Microsoft .NET Framework config tool.
Request for the permission of type:
'System.Data.OleDB.OleDbPermission, System.Data, Version = 2.0.0.0, culture=neutral, PublicKeyToekn=b77a56193e0489' Failed
I given all the rights for Users from Server System
even though it is giving error
Plz help me
thanks in advance
vijay kumar d
|
|
|
|
|
Your users do not have permission to connect to the database (oledb).
What is your database?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
have you ever heard of CAS
Your users have no permissions to execute the .NET code. Do your users run your App from a network share? If so its not a good idea.if its awin App copy it from the share and install it locally
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
I am looking for documentation on how to do the following. I want to see some examples on how to print to a template document. For example an invoice. I assume I need to specify the xy coordinates. But, I can't find or don't know what to put in to search engine to get documentation on this.
Can someone please help me?
Thank you.
|
|
|
|
|
It's rendered the same way you do things in a forn or control's paint event. You have to render strings of text and graphics in certain locations the just happen to be where the fields are on the page.
Settying this up is quite a time consuming, trial-and-error process, so be prepared to go through a lot of paper.
On the other hand, you might want to consider using a forms library, like Adobe Acrobat to layout you fields, then have your code fill them in using Acrobat Reaer. When that's done, you can have Acrobat Reader print the finished form.
|
|
|
|
|
If your data for the invoice is in a windows form (textboxes and labels etc.) then the Form Print Control[^] can turn this into a printed page style document and allows you to control the x,y, font, colour and so on of the generated output.
|
|
|
|
|
hi,
how can i communicate with a bluetooth gps in vb.net?
i've an usb bluetooth and i would recive from gps nmea string latitude and longitude.
how can i do this in vb.net and visual studio 2005/08?
|
|
|
|
|
|
Dumb question, but what's the best and easiest way to persist all of the form sizes (and perhaps other information, such as datagridview column layouts) across sessions?
Thanks
|
|
|
|
|
Write your own serializer to save all this information when the app/form closes and reload it, setting all the appropriate properties, the next time the app/form is created.
|
|
|
|
|