473,549 Members | 2,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ActiveX control written in C# Socket problem

I have been working on an ActiveX control in C#. It is packaged in a Windows Control library and the code is in a user control. The control is used as an automation receiver that is used to update a page dynamically through the use of event listeners in javascript
That works, the problem is that when I run the test webpage that runs the ActiveX control, the socket does not start listening for about a minute and a half, after which it runs fine. My initial thoughts are that this is an iis problem. When I run the test webpage, I check netstat to see if my socket is listening, and it is, but I get all these time_wait connections, these eventually die out and are completely closed, and I am finally able to use my control properly

netstat -

Active Connection

Proto Local Address Foreign Address Stat
â€
TCP *:http localhost:4444 ESTABLISHE
TCP *:http localhost:4446 TIME_WAI
TCP *:http localhost:4448 TIME_WAI
TCP *:http localhost:4450 TIME_WAI
TCP *:http localhost:4452 TIME_WAI
TCP *:http localhost:4454 TIME_WAI
TCP *:http localhost:4456 TIME_WAI
TCP *:http localhost:4458 TIME_WAI
TCP *:http localhost:4460 TIME_WAI
TCP *:http localhost:4462 TIME_WAI
TCP *:http localhost:4465 TIME_WAI
TCP *:http localhost:4466 ESTABLISHE
TCP *:4421 localhost:http TIME_WAI
TCP *:4444 localhost:http ESTABLISHE
TCP *:4466 localhost:http ESTABLISHE
â€
UDP *:55557 *:
…
Does anyone have an idea why this is happening, I need this control to listen instantly. I am not completely sure that the time_waits have anything to do with this problem but I am at a loss to explain it, and I need to get this completed
The code for the ActiveX Control is
using System
using System.Componen tModel
using System.Drawing
using System.Windows. Forms
using System.Runtime. InteropServices
using System.Net
using System.Net.Sock ets
using System.Threadin g

namespace LiveContro

public delegate void EventHandler(st ring Message)

[GuidAttribute(" 47209E59-A736-4c14-AD57-201E5162C297")
[InterfaceTypeAt tribute(ComInte rfaceType.Inter faceIsIDispatch )
public interface ILiveContro

[DispIdAttribute (0x60020000)
void MessageNotify(s tring Message);
public interface ILiveControlPub li

string MultiCastIP {get; set;
int MultiCastPort { get; set;
int MultiCastTTL { get; set;
int CharLimit { get; set;
void CloseSocket();

[ClassInterface( ClassInterfaceT ype.AutoDispatc h),ComSourceInt erfaces(typeof( ILiveControl))
public class MultiCast : System.Windows. Forms.UserContr ol, ILiveControlPub li

private string _multiCastIP
private int _multiCastPort
private int _multiCastTTL;
private Socket _receiveSocket
private string _multiCastMessa ge
private int _charLimit = 25000
private Thread trd = null

public string MultiCastI

get { return _multiCastIP;
set {_multiCastIP = value;

public int MultiCastPor

get { return _multiCastPort;
set {_multiCastPort = value;

public int MultiCastTT

get { return _multiCastTTL;
set {_multiCastTTL = value;

public string MultiCastMessag

get { return _multiCastMessa ge;
set {_multiCastMess age = value;

public int CharLimi

get { return _charLimit;
set {_charLimit = value;

event EventHandler MessageNotify

public MultiCast(

trd = new Thread(new ThreadStart(thi s.StartListenin g))
trd.IsBackgroun d = true
trd.Start()
#region Socket Method
public void CloseSocket(

trd.Suspend()
trd.Abort()
_receiveSocket. Shutdown(Socket Shutdown.Both)
_receiveSocket. Close()

private void StartListening(

tr
{
// initialize socke
_receiveSocket = new Socket(AddressF amily.InterNetw ork,SocketType. Dgram,ProtocolT ype.Udp)

IPEndPoint ipept = new IPEndPoint(IPAd dress.Any, _multiCastPort)

//bind socket to IPEndPoint
_receiveSocket. Bind(ipept);

IPAddress ip = IPAddress.Parse (_multiCastIP);

_receiveSocket. SetSocketOption (SocketOptionLe vel.IP,SocketOp tionName.AddMem bership,
new MulticastOption (ip));
byte[] MessageBuffer = new byte[_charLimit];
//listening loop
while(true)
{
_receiveSocket. Receive(Message Buffer);

//transform received byte[] to string
_multiCastMessa ge = System.Text.Enc oding.ASCII.Get String(MessageB uffer);
if(_multiCastMe ssage.Length > 0)
{
// Broadcast Message to event listeners if they exist
if (MessageNotify != null)
{
//fire event MessageNotify(_ multiCastMessag e);
}
}
}
}
catch (Exception ex)
{
// Broadcast Message to event listeners if they exist
if (MessageNotify != null)
{
//fire event
MessageNotify(e x.Message);
}
}
finally
{
//Should never get here but just in case close the socket
_receiveSocket. Close();
}
}
#endregion
}
}

This is called in the webpage;

<body onunload="Unloa d();"><form id="Form1" method="post" runat="server"> <object id=LiveControl classid=LiveCon trol.dll#LiveCo ntrol.MultiCast VIEWASTEXT><par am name="MultiCast IP" value="*.*.*.*" ><param name="MultiCast Port" value=55557><pa ram name="MultiCast TTL" value=16><param name="CharLimit " value=50000></object><script language="javas cript">
function Unload()
{
document.Form1. LiveControl.Clo seSocket();
}
</script><script language=javasc ript for=LiveControl event="MessageN otify(a)">
alert(a);
</script>
Jul 21 '05 #1
1 3020
after further examination of the problem. I have found that when the multicast is sent the receiving socket automatically receives the datagram, the problem is that 3 new tcp process are created

iexplore.exe:pr ocess# tcp 0.0.0.0:2961 0.0.0.0:0 listenin
inetinfo.exe:in etinfoprocess# tcp 127.0.0.1:80 127.0.0.1:2961 establishe
iexplore.exe:pr ocess# tcp 127.0.0.1:2961 127.0.0.1:80 establishe

until these close out after a minute and forty seconds everytime, i dont 'receive' the packet. any time after that i receive immediately. I believe this has something to do with the fact that the listener is run in a Com objectand that i may have declared it incorrectly.
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2705
by: Steve | last post by:
I am having an issue deploying an ActiveX control. This is a .NET project in C#. The ActiveX control is written in VB6. I use the PDW (Package and Deployment Wizard) to create a .CAB for the control. The problem is that sometimes the ActiveX control installs successfully and sometimes it doesn't. We have various test machines running...
1
2283
by: Bryan | last post by:
I have created an MFC ActiveX control. If I connect to my local machine on some port, everything works fine. If I try to connect to a different computer, I get an error (from CSocket.Create) that says "The requested address is not valid in its context." I know for a fact that the address is valid because I can have one of my Java Programs...
1
1496
by: CSharpNewBie | last post by:
Hi I have a ActiveX control (TcpSocket Client) which has 3 Events OnConnect/OnDisconnect and OnEvent. my question is how do I embed this non-visual control on a aspx webpage and create a OnEvent Handler which receives data from a Tcp Server and add that to dataset to be displayed on DataGrid. This works fine a on Windows Application.
1
365
by: mjcast | last post by:
I have been working on an ActiveX control in C#. It is packaged in a Windows Control library and the code is in a user control. The control is used as an automation receiver that is used to update a page dynamically through the use of event listeners in javascript That works, the problem is that when I run the test webpage that runs the ActiveX...
2
2868
by: Wael_Bakr | last post by:
I have a dll written in visual basic.net, I need to run this dll on client's machine, so if i need to wrap it as an activex control to be downloaded on client's machine how can i do this using visual studio 2003 or 2005 other than visual basic 6 or visual c++ ??
1
5153
by: Frank | last post by:
Short Version of Question: Can anyone provide an example of how I should embed the ActiveX and license, and then use it in a function?
0
1319
by: Frank | last post by:
Short Version of Question: Can anyone provide an example of how I should embed the ActiveX and license, and then use it in a function?
1
1576
by: david | last post by:
I have the following question about them and need your help. 1. Can ActiveX control open a socket in client machine to connect to a third machine other than web server? 2. Can ActiveX control invoke a client side application? I remember it can before. Any restriction on it? 3. Same questions to Java Applet within Web browser. Thank you...
11
3316
by: Tim | last post by:
hi, I would like to create an application that runs in a web browser. It must have access to the client machine. I guess a bit like the microsoft update tool at windowsupdate.com Having never created anything like this, can anyone point me in the right direction? I am using VB.NET2005 Thanks
0
7542
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7736
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7982
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7500
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7827
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6066
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5110
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3514
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1961
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.