473,406 Members | 2,705 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,406 software developers and data experts.

User Control - Socket create freeze browser

Hi,

I have to make an ActiveX (Running on Internet Explorer) that
play/record sound from soundcard. Also, I have to create a Socket to
send/receive sound data to my server.

I use this tutorial to build my ActiveX :
http://samples.gotdotnet.com/quickst...eSourcing.aspx

When creating Socket object on client I got SecurityException. So I
resolved the problem by adding LocalIntranet_Zone (FullTrust) for my
server http://localhost/*.

Now I' m create the Socket object as :
_______________________________________________
// Get IP and port of remote host
IPEndPoint ep = new IPEndPoint(Dns.Resolve(m_IPAddress).AddressList[0],
m_PortNumber);

// Connect
m_ClientSocket.Connect(ep);

// Start received thread
Thread clientThread = new Thread(new ThreadStart(ReceiveThread));
clientThread.Name = "Client thread";
clientThread.Start();

// Back to ActiveX thread....
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Here is the Thread code :
________________________________________________
// Client is running
m_bIsRunning = true;

// Client is running
m_bIsThreadStopped = false;

// While client is running then read incomming data
while (m_bIsRunning)
{
// Start receive thread
try
{
byte[] buffer = new byte[this.m_ReceiveBufferSize];
int iBytesCount = this.m_ClientSocket.Receive(buffer, 0,
this.m_ReceiveBufferSize, SocketFlags.None); ;
if (iBytesCount == 0)
break;

// Raise data sent event
ClientDataReceivedEvent( new MemoryStream( buffer, 0,
iBytesCount ) );
}
catch (Exception ex)
{
if (m_bIsRunning)
ClientErrorOccuredEvent( ex );
break;
}
}

// Thread end
m_bIsRunning = false;

// Client disconnected
ClientDisconnectedEvent();

// Thread stopped
m_bIsThreadStopped = true;
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

Now whatever I do the ActiveX is freezing Internet Explorer just when
this Thread is starting. What is the problem ?

Thanks for your help

Jul 28 '06 #1
3 2480
Erakis,

First, what you are doing is NOT creating an ActiveX control. It is a
..NET control hosted in Internet Explorer.

As for why it freezes up, you are running in this loop looking for data
to come down the wire. If there is no data on the wire, you are most likely
blocking on your main thread, which is causing the problem.

Also, your m_bIsRunning needs to be protected with a lock statement in
order to access the variable correctly.

Are you running in a loop on your UI thread checking m_bIsRunning? That
could also be a problem.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Erakis" <er******@hotmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hi,

I have to make an ActiveX (Running on Internet Explorer) that
play/record sound from soundcard. Also, I have to create a Socket to
send/receive sound data to my server.

I use this tutorial to build my ActiveX :
http://samples.gotdotnet.com/quickst...eSourcing.aspx

When creating Socket object on client I got SecurityException. So I
resolved the problem by adding LocalIntranet_Zone (FullTrust) for my
server http://localhost/*.

Now I' m create the Socket object as :
_______________________________________________
// Get IP and port of remote host
IPEndPoint ep = new IPEndPoint(Dns.Resolve(m_IPAddress).AddressList[0],
m_PortNumber);

// Connect
m_ClientSocket.Connect(ep);

// Start received thread
Thread clientThread = new Thread(new ThreadStart(ReceiveThread));
clientThread.Name = "Client thread";
clientThread.Start();

// Back to ActiveX thread....
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Here is the Thread code :
________________________________________________
// Client is running
m_bIsRunning = true;

// Client is running
m_bIsThreadStopped = false;

// While client is running then read incomming data
while (m_bIsRunning)
{
// Start receive thread
try
{
byte[] buffer = new byte[this.m_ReceiveBufferSize];
int iBytesCount = this.m_ClientSocket.Receive(buffer, 0,
this.m_ReceiveBufferSize, SocketFlags.None); ;
if (iBytesCount == 0)
break;

// Raise data sent event
ClientDataReceivedEvent( new MemoryStream( buffer, 0,
iBytesCount ) );
}
catch (Exception ex)
{
if (m_bIsRunning)
ClientErrorOccuredEvent( ex );
break;
}
}

// Thread end
m_bIsRunning = false;

// Client disconnected
ClientDisconnectedEvent();

// Thread stopped
m_bIsThreadStopped = true;
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

Now whatever I do the ActiveX is freezing Internet Explorer just when
this Thread is starting. What is the problem ?

Thanks for your help
Jul 28 '06 #2
Hi,

First I want to thanks you for your help.
I put a button on my ActiveX and here is the onclick code :
__________________________________________________
private void button1_Click(object sender, System.EventArgs e)
{
m_TCPClient = new TCPClient( "192.168.2.98", 5555 );
m_TCPClient.Connect();
}
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

Now here is the TCPClient Connect method
__________________________________________________
public void Connect()
{
IPEndPoint ep = new
IPEndPoint(Dns.Resolve(m_IPAddress).AddressList[0], m_PortNumber);

// Connect
m_ClientSocket.Connect(ep);

// Start received thread
Thread clientThread = new Thread(new ThreadStart(ReceiveThread));
clientThread.Name = "Client thread";
clientThread.Start();

// I'm am not BLOCKING my Control UI thread because I'm starting a
new thread
// from there and the CPU goes back to UI. No ?
}
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

I have test this Control into on a Winform project and I have no
problem, form isn't freezing.
Thanks
Nicholas Paldino [.NET/C# MVP] wrote:
Erakis,

First, what you are doing is NOT creating an ActiveX control. It is a
.NET control hosted in Internet Explorer.

As for why it freezes up, you are running in this loop looking for data
to come down the wire. If there is no data on the wire, you are most likely
blocking on your main thread, which is causing the problem.

Also, your m_bIsRunning needs to be protected with a lock statement in
order to access the variable correctly.

Are you running in a loop on your UI thread checking m_bIsRunning? That
could also be a problem.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Erakis" <er******@hotmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hi,

I have to make an ActiveX (Running on Internet Explorer) that
play/record sound from soundcard. Also, I have to create a Socket to
send/receive sound data to my server.

I use this tutorial to build my ActiveX :
http://samples.gotdotnet.com/quickst...eSourcing.aspx

When creating Socket object on client I got SecurityException. So I
resolved the problem by adding LocalIntranet_Zone (FullTrust) for my
server http://localhost/*.

Now I' m create the Socket object as :
_______________________________________________
// Get IP and port of remote host
IPEndPoint ep = new IPEndPoint(Dns.Resolve(m_IPAddress).AddressList[0],
m_PortNumber);

// Connect
m_ClientSocket.Connect(ep);

// Start received thread
Thread clientThread = new Thread(new ThreadStart(ReceiveThread));
clientThread.Name = "Client thread";
clientThread.Start();

// Back to ActiveX thread....
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Here is the Thread code :
________________________________________________
// Client is running
m_bIsRunning = true;

// Client is running
m_bIsThreadStopped = false;

// While client is running then read incomming data
while (m_bIsRunning)
{
// Start receive thread
try
{
byte[] buffer = new byte[this.m_ReceiveBufferSize];
int iBytesCount = this.m_ClientSocket.Receive(buffer, 0,
this.m_ReceiveBufferSize, SocketFlags.None); ;
if (iBytesCount == 0)
break;

// Raise data sent event
ClientDataReceivedEvent( new MemoryStream( buffer, 0,
iBytesCount ) );
}
catch (Exception ex)
{
if (m_bIsRunning)
ClientErrorOccuredEvent( ex );
break;
}
}

// Thread end
m_bIsRunning = false;

// Client disconnected
ClientDisconnectedEvent();

// Thread stopped
m_bIsThreadStopped = true;
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

Now whatever I do the ActiveX is freezing Internet Explorer just when
this Thread is starting. What is the problem ?

Thanks for your help
Jul 31 '06 #3
Hi,

Finally I found two solution of this problem :
-
http://www.velocityreviews.com/forum...d-control.html
-
http://groups.google.ca/group/micros...16c56f73791bc9

Thanks anyway for you help :)
Chow
Erakis wrote:
Hi,

First I want to thanks you for your help.
I put a button on my ActiveX and here is the onclick code :
__________________________________________________
private void button1_Click(object sender, System.EventArgs e)
{
m_TCPClient = new TCPClient( "192.168.2.98", 5555 );
m_TCPClient.Connect();
}
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

Now here is the TCPClient Connect method
__________________________________________________
public void Connect()
{
IPEndPoint ep = new
IPEndPoint(Dns.Resolve(m_IPAddress).AddressList[0], m_PortNumber);

// Connect
m_ClientSocket.Connect(ep);

// Start received thread
Thread clientThread = new Thread(new ThreadStart(ReceiveThread));
clientThread.Name = "Client thread";
clientThread.Start();

// I'm am not BLOCKING my Control UI thread because I'm starting a
new thread
// from there and the CPU goes back to UI. No ?
}
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

I have test this Control into on a Winform project and I have no
problem, form isn't freezing.
Thanks
Nicholas Paldino [.NET/C# MVP] wrote:
Erakis,

First, what you are doing is NOT creating an ActiveX control. It is a
.NET control hosted in Internet Explorer.

As for why it freezes up, you are running in this loop looking for data
to come down the wire. If there is no data on the wire, you are most likely
blocking on your main thread, which is causing the problem.

Also, your m_bIsRunning needs to be protected with a lock statementin
order to access the variable correctly.

Are you running in a loop on your UI thread checking m_bIsRunning? That
could also be a problem.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Erakis" <er******@hotmail.comwrote in message
news:11*********************@i42g2000cwa.googlegro ups.com...
Hi,

I have to make an ActiveX (Running on Internet Explorer) that
play/record sound from soundcard. Also, I have to create a Socket to
send/receive sound data to my server.

I use this tutorial to build my ActiveX :
http://samples.gotdotnet.com/quickst...Sourcing..aspx

When creating Socket object on client I got SecurityException. So I
resolved the problem by adding LocalIntranet_Zone (FullTrust) for my
server http://localhost/*.

Now I' m create the Socket object as :
_______________________________________________
// Get IP and port of remote host
IPEndPoint ep = new IPEndPoint(Dns.Resolve(m_IPAddress).AddressList[0],
m_PortNumber);

// Connect
m_ClientSocket.Connect(ep);

// Start received thread
Thread clientThread = new Thread(new ThreadStart(ReceiveThread));
clientThread.Name = "Client thread";
clientThread.Start();

// Back to ActiveX thread....
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Here is the Thread code :
________________________________________________
// Client is running
m_bIsRunning = true;

// Client is running
m_bIsThreadStopped = false;

// While client is running then read incomming data
while (m_bIsRunning)
{
// Start receive thread
try
{
byte[] buffer = new byte[this.m_ReceiveBufferSize];
int iBytesCount = this.m_ClientSocket.Receive(buffer, 0,
this.m_ReceiveBufferSize, SocketFlags.None); ;
if (iBytesCount == 0)
break;

// Raise data sent event
ClientDataReceivedEvent( new MemoryStream( buffer, 0,
iBytesCount ) );
}
catch (Exception ex)
{
if (m_bIsRunning)
ClientErrorOccuredEvent( ex );
break;
}
}

// Thread end
m_bIsRunning = false;

// Client disconnected
ClientDisconnectedEvent();

// Thread stopped
m_bIsThreadStopped = true;
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

Now whatever I do the ActiveX is freezing Internet Explorer just when
this Thread is starting. What is the problem ?

Thanks for your help
Jul 31 '06 #4

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

Similar topics

0
by: Fuzzyman | last post by:
I'm trying to create a proxy server - one that will modify requests made through it. I've started with Tiny HTTP Proxy by SUZUKI Hisao which is built on BaseHTTPServer - and I'm starting to get...
0
by: TJ | last post by:
Dear Sir/Madm Environmen ..NET runtime 1. IE 6. I made one User Control form to host in Internet Explorer class MyUserControl : UserControl ... void ConnectToServer()
0
by: RonNanko | last post by:
Hi, let me first explain what my problem is all about: I have a third-party application, which does not allow multiple instances of itself. As I need to run the application in multiple instances...
4
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
7
by: kris_scheyer | last post by:
Hi, I have a little .exe file that I want the C# code behind of my web application to execute as a different user. The executable is supposed to take a screenshot of the server's display and...
5
by: Segfahlt | last post by:
I need a little help here please. I have 2 win forms user controls in 2 different projects that I'm hosting in 2 different virtual directories. The controls have been test and operate okay in...
6
by: Luis P. Mendes | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I've developed a program that uses a socket to receive information 24h a ~ day. The problem is that the socket seems to freeze. By that I...
5
by: Richard Maher | last post by:
Hi, Here I mean "User" in the Programmer or Javascript sense. I merely wish to programmatically trigger an Event. It would be absolutely fantastic if there was a (Form level?) ONUSEREVENT() and...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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...
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
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...
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.