User Control - Socket create freeze browser

E

Erakis

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/quickstart/winforms/doc/WinFormsIeSourcing.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
 
N

Nicholas Paldino [.NET/C# MVP]

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]
- (e-mail address removed)



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/quickstart/winforms/doc/WinFormsIeSourcing.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
 
E

Erakis

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

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]
- (e-mail address removed)



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/quickstart/winforms/doc/WinFormsIeSourcing.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
 
E

Erakis

Hi,

Finally I found two solution of this problem :
-
http://www.velocityreviews.com/foru...connection-from-within-ie-hosted-control.html
-
http://groups.google.ca/group/micro...91bc9?lnk=st&q=&rnum=3&hl=en#c916c56f73791bc9

Thanks anyway for you help :)
Chow

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

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]
- (e-mail address removed)



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/quickstart/winforms/doc/WinFormsIeSourcing..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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top