473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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.ComponentModel
using System.Drawing
using System.Windows.Forms
using System.Runtime.InteropServices
using System.Net
using System.Net.Sockets
using System.Threading

namespace LiveContro

public delegate void EventHandler(string Message)

[GuidAttribute("47209E59-A736-4c14-AD57-201E5162C297")
[InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIDispatch)
public interface ILiveContro

[DispIdAttribute(0x60020000)
void MessageNotify(string Message);
public interface ILiveControlPubli

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

[ClassInterface(ClassInterfaceType.AutoDispatch),Co mSourceInterfaces(typeof(ILiveControl))
public class MultiCast : System.Windows.Forms.UserControl, ILiveControlPubli

private string _multiCastIP
private int _multiCastPort
private int _multiCastTTL;
private Socket _receiveSocket
private string _multiCastMessage
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 _multiCastMessage;
set {_multiCastMessage = value;

public int CharLimi

get { return _charLimit;
set {_charLimit = value;

event EventHandler MessageNotify

public MultiCast(

trd = new Thread(new ThreadStart(this.StartListening))
trd.IsBackground = true
trd.Start()
#region Socket Method
public void CloseSocket(

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

private void StartListening(

tr
{
// initialize socke
_receiveSocket = new Socket(AddressFamily.InterNetwork,SocketType.Dgram ,ProtocolType.Udp)

IPEndPoint ipept = new IPEndPoint(IPAddress.Any, _multiCastPort)

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

IPAddress ip = IPAddress.Parse(_multiCastIP);

_receiveSocket.SetSocketOption(SocketOptionLevel.I P,SocketOptionName.AddMembership,
new MulticastOption(ip));
byte[] MessageBuffer = new byte[_charLimit];
//listening loop
while(true)
{
_receiveSocket.Receive(MessageBuffer);

//transform received byte[] to string
_multiCastMessage = System.Text.Encoding.ASCII.GetString(MessageBuffer );
if(_multiCastMessage.Length > 0)
{
// Broadcast Message to event listeners if they exist
if (MessageNotify != null)
{
//fire event MessageNotify(_multiCastMessage);
}
}
}
}
catch (Exception ex)
{
// Broadcast Message to event listeners if they exist
if (MessageNotify != null)
{
//fire event
MessageNotify(ex.Message);
}
}
finally
{
//Should never get here but just in case close the socket
_receiveSocket.Close();
}
}
#endregion
}
}

This is called in the webpage;

<body onunload="Unload();"><form id="Form1" method="post" runat="server"><object id=LiveControl classid=LiveControl.dll#LiveControl.MultiCast VIEWASTEXT><param name="MultiCastIP" value="*.*.*.*"><param name="MultiCastPort" value=55557><param name="MultiCastTTL" value=16><param name="CharLimit" value=50000></object><script language="javascript">
function Unload()
{
document.Form1.LiveControl.CloseSocket();
}
</script><script language=javascript for=LiveControl event="MessageNotify(a)">
alert(a);
</script>
Jul 21 '05 #1
1 2999
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:process# tcp 0.0.0.0:2961 0.0.0.0:0 listenin
inetinfo.exe:inetinfoprocess# tcp 127.0.0.1:80 127.0.0.1:2961 establishe
iexplore.exe:process# 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
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...
1
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...
1
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...
1
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...
2
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...
1
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
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
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...
11
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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,...

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.