Visual Basic .NET » Internet / Hardware Communication
TCP Socket.connect needs more than 1 Minute to execute when invoked over Browser -- Chris --


The following constellation: We have a .NET (1.1) application
(Visualisation) programmed under VS2003) on a webserver (IIS). This application gets loaded from a client PC and is executed over the assembly cache. There are 2 methods to do so:
Method 1. we invoke the Visualisation application over a little programm (Loader). The code is shown below!
Method 2. we start the Visualisation application over the IE (Browser)
The application is then connecting to the socket of the webserver. With the following code:

private bool ConnectToServer(string ip) //in the IP Address of the IIS Server station where the application originates from
{
if ((ClientSocket!=null) && (ClientSocket.Connected==true))
{
MessageBox.Show("Client has already a connection to the server!\nOnly one connection is allowed.", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return (false);
}
try
{
IPEndPoint thisIP=new IPEndPoint(IPAddress.Parse(ip), VARCOMM_PORT);
MessageBox.Show("creating socket", "Debug 1", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
ClientSocket=new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
MessageBox.Show("invoking connect", "Debug 2", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
ClientSocket.Connect(thisIP);
//if application is started over a web browser then it takes up to 60seconds to exit the connect function!
MessageBox.Show("connect was successful", "Debug 3",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return (false);
}
ClientSocket.Blocking=false;
return(true);
}

With Method 1 it connects right away!
With Method 2 it takes more than 1 Minute to connect successful. After this time it is correctly connected (no error). But it takes dammed long! We also figured over Etherreal that the connection is already there but it seems that the connect function just takes a break before it terminates.

What is the reasen or what can be done?
Here the code for Method 1:
private void mStart_Click(object sender, System.EventArgs e)
{
ThreadAppPath="http://" + tbIPAddress.Text.ToString() +
"/Visualisation/Visualisation.exe";
if (rbThread.Checked)
{
Thread localThread = new Thread(new ThreadStart(StartAssembly));
localThread.Start();
}
if (rbExplorer.Checked)
{
Process.Start(ThreadAppPath); // uses Internet Explorer to load and execute the assembly
}
}

private void StartAssembly()
{
string path=ThreadAppPath;
try
{
AppDomain newDomain = AppDomain.CreateDomain("newDomain");
newDomain.ExecuteAssembly(path); // works fine
AppDomain.Unload(newDomain);
}
catch (Exception ex)
{
MessageBox.Show("Could not find and start the Visualisation!\n" +
ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

[Submit Comment]Home