| Dart Home | PowerTCP Sockets for .NET | Custom Development | Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums |
| Author | Forum: PowerTCP Sockets for .NET (Secure and Standard) Topic: Using the PowerTCP Component to create a custom server control |
| jeffreylreed From: Ashland, OR USA Posts: 9 Member Since: 07/01/03 |
posted July 1, 2003 3:30 PM Greetings, I am attempting to create a custom server control, but am running into some difficulties. I was wondering if anyone could provide an example of how to use the PowerTCP Component to create a custom server control (Custom DLL), preferable in C#. Any help would be appreciated. Thanks, -jr |
Jeff Cranford![]() From: Rome, NY USA Posts: 586 Member Since: 05/30/01 |
posted July 1, 2003 4:06 PM We're going to need a little more info. First of all, (just to be clear) are you referring to an ASP.NET Server Control? We don't have any specific server control examples but there shouldn't be any problems getting our stuff to work in one. What are you trying to do within the server control? What difficulties are you running into? |
| jeffreylreed From: Ashland, OR USA Posts: 9 Member Since: 07/01/03 |
posted July 1, 2003 5:01 PM Specifically, I am trying to create web parts based on Microsft SharePoint 2003. They are ASP.NET Server Controls, and are developed in the same way one would develop a standard server control with a few minor differences in that there are some additional classes for web parts, etc.. Additionally, unlike standard ASP.NET controls, which are added to Web form pages by programmers at design time, Web Parts are intended to be added to Web Part Zones on Web Part Pages by users at run time. All in all, once I have a good server control - converting it to a web part custom control is not too much work. I believe that your stuff will work in both a traditional server control and a web part server control, but it's too bad for me that you don't have any server control examples. Being new to PowerTCP it would have been very useful to analyze how to integrate using your product in this way. Maybe someone else will read this post and respond. Thanks for your help, -jr |
Jeff Cranford![]() From: Rome, NY USA Posts: 586 Member Since: 05/30/01 |
posted July 1, 2003 5:52 PM So, since you can easily convert a server control to a "web parts" control (I have no idea what that is, by the way) let's just take all of the "web parts" stuff out of the equation and focus on the server control aspect. Can you provide a very basic example of something you would like to see demonstrated in a server control using our product? We will not be able to write a sample (unless you wish to check into our custom development options) but I can at least give you some direction on how I would proceed in implementing whatever you are interested in. |
| jeffreylreed From: Ashland, OR USA Posts: 9 Member Since: 07/01/03 |
posted July 2, 2003 3:17 AM There are three pieces code here that demonstrate the progression of what I want to do. This is a simple script that has worked it's way down from Microsoft exemplifying a ping script, which I developed into a WebPart in the final stage. Code sample 1 shows the ASP.NET Server Control class, code sample 2 shows the windows form that goes with the ASP.NET Server Control class, and finally code sample 3 shows the WebPart that combines 1 and 2 together in the WebPart Server Control format. If you look at the first 60 or so lines in code sample 3 you'll see that it's just some using directives and some code to create a text box and a command button, everything after that is redundant from from code sample 1. I suspect that with the use of the PowerTCP Component this example would be simplified considerably. I realize that there is nearly 800 lines to this message, but there is no need to read it all to understand what's going on. One should be able to scan the first few lines from each section to understand. So what I want to know is how to get rid of all the code from the Ping Class and replace with PowerTCP Ping Class. If you can show me how to interface with your ping class in this way I should be off and running. See next three post for code samples... |
Jeff Cranford![]() From: Rome, NY USA Posts: 586 Member Since: 05/30/01 |
posted July 2, 2003 9:21 AM If you posted code, it didn't come through. No matter, as this forum is not indended for extensive code review. If you need this level of service, you have to speak with our sales department about support options. Here is a very simple server control I did in about 5 minutes which uses the Ping control. using System; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; using Dart.PowerTCP.Sockets; namespace PingControl { [ToolboxData("<{0}:MyPing runat=server></{0}:MyPing>")] public class MyPing : System.Web.UI.WebControls.WebControl { private string m_Text; private Ping m_Ping; public MyPing() : base(){} protected override void Render(HtmlTextWriter output) { output.Write(m_Text); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); m_Text = "Waiting for DoPing to be called"; m_Ping = new Ping(); } public void DoPing(string remoteHost, int iterations) { m_Ping.PingType = PingType.UDP; m_Text = "Pinging " + remoteHost + " " + iterations + " time(s).<br>"; for(int i = 0; i < iterations; i++) { m_Text+= "Ping #" + i; try { EchoResult e = m_Ping.Send(remoteHost); m_Text+= " Delay = " + e.ResponseTime + "<br>"; } catch(Exception ex) { m_Text+= " Failed. Reason = " + ex.Message; } } } } } Instructions: 1) Add a licenses.licx file to the project as described in the documentation. 2) Add a reference to the Dart.PowerTCP.Sockets.dll. 3) Compile this code to create the server control dll. 4) Add the server control to a web form. 5) Call DoPing from a button click or something (like so): MyPing1.DoPing("www.dart.com", 3); Also, let me provide additional info about using Ping in a web-based app. The standard ping type (ICMP) requires the user have admin rights (a Microsoft security measure). If you want to use to use this type of ping, you have to give admin rights to your IUSR_Servername account. That's why I used PingType.UDP in the example above. See the thread http://support.dart.com/postings?topicid=3247 . I hope this helps. |
| jeffreylreed From: Ashland, OR USA Posts: 9 Member Since: 07/01/03 |
posted July 3, 2003 2:04 AM Thanks for the example, it is greatly appreciated. I am still having some problems, though. The error decribed below is simular to the problems I have been experiencing with other methods, too. I created a control with your code and then crteated an aspx as follows. Any ideas? pingcontrol.aspx <%@ Page Language="C#" %> <%@ Register TagPrefix="spt" NameSpace="PingControl" Assembly="PingControl" %> <HTML> <HEAD> <script runat="server"> void ButtonClicked(object sender, EventArgs e) { MyPing.DoPing("www.dart.com", 3); } </script> </HEAD> <body> <form runat="server" ID="Form1"> <br> <asp:Button text="Submit" id="submit" onclick="ButtonClicked" runat="server" /> <br> </form> </body> </HTML> Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0120: An object reference is required for the nonstatic field, method, or property 'PingControl.MyPing.DoPing(string, int)' Source Error: Line 9: if(!(IsPostBack)) Line 10: { Line 11: MyPing.DoPing("www.dart.com", 3); Line 12: } Line 13: } Source File: c:\inetpub\wwwroot\pingcontrol.aspx Line: 11 |
| jeffreylreed From: Ashland, OR USA Posts: 9 Member Since: 07/01/03 |
posted July 3, 2003 2:10 AM Actually, here is the error when I attempt to run the aspx page. The one posted above is one during trouble shooting. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0120: An object reference is required for the nonstatic field, method, or property 'PingControl.MyPing.DoPing(string, int)' Source Error: Line 7: void ButtonClicked(object sender, EventArgs e) Line 8: { Line 9: MyPing.DoPing("www.dart.com", 3); Line 10: } Line 11: </script> Source File: c:\inetpub\wwwroot\pingcontrol.aspx Line: 9 |
Jeff Cranford![]() From: Rome, NY USA Posts: 586 Member Since: 05/30/01 |
posted July 3, 2003 11:40 AM Looks like you are missing a <spt:MyPing id=MyPing1 runat="server"></spt:MyPing> in your aspx file. |
| jeffreylreed From: Ashland, OR USA Posts: 9 Member Since: 07/01/03 |
posted July 3, 2003 1:26 PM Yes, your were right, Thanks. Thank you for your help and patience as I'm getting close to figuring this out. I have made IUSR_Servername a member of the administrators group yet I recieve the following errors under three configurations; ICMP Pinging www.dart.com 3 time(s). Ping #0 Failed. Reason = An attempt was made to access a socket in a way forbidden by its access permissionsPing #1 Failed. Reason = An attempt was made to access a socket in a way forbidden by its access permissionsPing #2 Failed. Reason = An attempt was made to access a socket in a way forbidden by its access permissions UDP Pinging www.dart.com 3 time(s). Ping #0 Failed. Reason = Host port in use and thus invalidPing #1 Failed. Reason = Host port in use and thus invalidPing #2 Failed. Reason = Host port in use and thus invalid TCP Pinging www.dart.com 3 time(s). Ping #0 Failed. Reason = Host port in use and thus invalidPing #1 Failed. Reason = Host port in use and thus invalidPing #2 Failed. Reason = Host port in use and thus invalid |
Jeff Cranford![]() From: Rome, NY USA Posts: 586 Member Since: 05/30/01 |
posted July 3, 2003 1:46 PM The problem you are having with the TCP and UDP pings is a known issue. The ICMP ping should work with Admin rights on your IUSR account. You probably want to also check out the MS Knowledge base article about this at http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q195445 and see if it applies to you. It has registry editing instructions as a workaround to this problem. |
| jeffreylreed From: Ashland, OR USA Posts: 9 Member Since: 07/01/03 |
posted July 3, 2003 2:08 PM Yes, I read that from a prior posts. However, whe you first posted the example you stated; " ...The standard ping type (ICMP) requires the user have admin rights (a Microsoft security measure). If you want to use to use this type of ping, you have to give admin rights to your IUSR_Servername account. That's why I used PingType.UDP in the example above." This seems to imply that PingType.UDP would work, but it does not - even if IUSR_Servername account has admin rights. I have tried to use PowerTCP with TCP, UDP and ICMP. Does this mean that PowerTCP only works under NT? Additionally, According to the MS Knowledge base article: "In Windows 2000, there is no way to disable this security check. Access to Raw Sockets is granted on a per-transport basis. For the address family AF_INET, only administrators have the access necessary to create Raw Sockets." |
| Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums |
This site is powered by
PowerTCP WebServer for ActiveX
|