Socket Exception:{"An existing connection was forcibly closed by the remote host"}
-
I am doing .Net Remoting and i get following exception what can be the reason?:confused: 1. Interface
public interface DeptInterface { bool ExecuteSelectCommand(string selcommand); string GetRow(); void Init(); } 2. Server.cs // which implements ClassLibrary Methods `public partial class Form1 : Form { public Form1() { InitializeComponent(); } public class CustServer : MarshalByRefObject, DeptInterface { private SqlConnection myConnection = null; private SqlDataReader myReader; public CustServer() { } public void Init() { try { String strConn = "Data Source=KPTEST1;Initial Catalog=Store;Integrated Security=SSPI"; myConnection = new SqlConnection(strConn); myConnection.Open(); if (myConnection == null) { MessageBox.Show("OPEN NULL VALUE ====================="); return; } } catch (Exception es) { MessageBox.Show("[Error WITH DB CONNECT...] " + es.Message); } } public bool ExecuteSelectCommand(String selCommand) { try { MessageBox.Show("EXECUTING .. " + selCommand); SqlCommand myCommand = new SqlCommand(selCommand); if (myConnection == null) { MessageBox.Show("NULL VALUE ====================="); return false; } myCommand.Connection = myConnection; myCommand.ExecuteNonQuery(); myReader = myCommand.ExecuteReader(); return true; } public string GetRow() { if (!myReader.Read()) { myReader.Close(); return ""; } int nCol = myReader.FieldCount; string outstr = ""; object[] values = new Object[nCol]; myReader.GetValues(values); for (int i = 0; i < values.Length; i++) { string coldata = values[i].ToString(); coldata = coldata.TrimEnd(); outstr += coldata + ","; } return outstr; }` Client.cs `private void Form1_Load(object sender, EventArgs e) { MessageBox.Show("TEST1"); bool ensureSecurity = true; ChannelServices.RegisterChannel(new TcpClientChannel(), ensureSecurity); dept = (DeptInterface)Activator.GetObject(typeof(DeptInterface), "tcp://KPTEST1:8080/CustServer"); if (dept == null) { MessageBox.Show("TCP SERVER OFFLINE ...PLEASE TRY LATER"); return; } dept.Init(); // Exception Error MessageBox.Show("TEST2"); }` It gives exception at dept.Init() ? What can be the reason please help me... :(
-
I'm guessing that just by the error message the other machine you're connecting to doesn't want to be connected. A firewall perhaps?
Ed, I am doing on the same machine localhost. By the way when i removed ChannelRegistry from Client.cs I am getting now following exception: System.Runtime.RemotingException: Requested Service not found at dept.Init() method. HELP :((((
-
I am doing .Net Remoting and i get following exception what can be the reason?:confused: 1. Interface
public interface DeptInterface { bool ExecuteSelectCommand(string selcommand); string GetRow(); void Init(); } 2. Server.cs // which implements ClassLibrary Methods `public partial class Form1 : Form { public Form1() { InitializeComponent(); } public class CustServer : MarshalByRefObject, DeptInterface { private SqlConnection myConnection = null; private SqlDataReader myReader; public CustServer() { } public void Init() { try { String strConn = "Data Source=KPTEST1;Initial Catalog=Store;Integrated Security=SSPI"; myConnection = new SqlConnection(strConn); myConnection.Open(); if (myConnection == null) { MessageBox.Show("OPEN NULL VALUE ====================="); return; } } catch (Exception es) { MessageBox.Show("[Error WITH DB CONNECT...] " + es.Message); } } public bool ExecuteSelectCommand(String selCommand) { try { MessageBox.Show("EXECUTING .. " + selCommand); SqlCommand myCommand = new SqlCommand(selCommand); if (myConnection == null) { MessageBox.Show("NULL VALUE ====================="); return false; } myCommand.Connection = myConnection; myCommand.ExecuteNonQuery(); myReader = myCommand.ExecuteReader(); return true; } public string GetRow() { if (!myReader.Read()) { myReader.Close(); return ""; } int nCol = myReader.FieldCount; string outstr = ""; object[] values = new Object[nCol]; myReader.GetValues(values); for (int i = 0; i < values.Length; i++) { string coldata = values[i].ToString(); coldata = coldata.TrimEnd(); outstr += coldata + ","; } return outstr; }` Client.cs `private void Form1_Load(object sender, EventArgs e) { MessageBox.Show("TEST1"); bool ensureSecurity = true; ChannelServices.RegisterChannel(new TcpClientChannel(), ensureSecurity); dept = (DeptInterface)Activator.GetObject(typeof(DeptInterface), "tcp://KPTEST1:8080/CustServer"); if (dept == null) { MessageBox.Show("TCP SERVER OFFLINE ...PLEASE TRY LATER"); return; } dept.Init(); // Exception Error MessageBox.Show("TEST2"); }` It gives exception at dept.Init() ? What can be the reason please help me... :(
-
shah123 wrote:
What can be the reason
I don't see anywhere in your server code where you setup the Tcp Channel that you are trying to use in the client.
Sorry it was in Server Form_Load method.
private void Form1_Load(object sender, EventArgs e) { TcpServerChannel tsc = new TcpServerChannel(8080); ChannelServices.RegisterChannel(tsc); RemotingConfiguration.RegisterWellKnownServiceType(typeof(CustServer), "CUSTOMER_SERVER2", WellKnownObjectMode.Singleton); textBox1.Text = "SERVER RUNNING .."; textBox1.ReadOnly=true; }
-
Sorry it was in Server Form_Load method.
private void Form1_Load(object sender, EventArgs e) { TcpServerChannel tsc = new TcpServerChannel(8080); ChannelServices.RegisterChannel(tsc); RemotingConfiguration.RegisterWellKnownServiceType(typeof(CustServer), "CUSTOMER_SERVER2", WellKnownObjectMode.Singleton); textBox1.Text = "SERVER RUNNING .."; textBox1.ReadOnly=true; }
-
shah123 wrote:
DeptInterface
I don't think you can register a "CustServer" and then in the client Activate a "DeptInterface". Also with Remoting, I recommend using namespaces.
so please tell me the way... I will be very thankful to you.
-
Ed, I am doing on the same machine localhost. By the way when i removed ChannelRegistry from Client.cs I am getting now following exception: System.Runtime.RemotingException: Requested Service not found at dept.Init() method. HELP :((((
-
this is not fair to me :( anyway if u dont want to help. Its ok
-
this is not fair to me :( anyway if u dont want to help. Its ok
-
I am doing .Net Remoting and i get following exception what can be the reason?:confused: 1. Interface
public interface DeptInterface { bool ExecuteSelectCommand(string selcommand); string GetRow(); void Init(); } 2. Server.cs // which implements ClassLibrary Methods `public partial class Form1 : Form { public Form1() { InitializeComponent(); } public class CustServer : MarshalByRefObject, DeptInterface { private SqlConnection myConnection = null; private SqlDataReader myReader; public CustServer() { } public void Init() { try { String strConn = "Data Source=KPTEST1;Initial Catalog=Store;Integrated Security=SSPI"; myConnection = new SqlConnection(strConn); myConnection.Open(); if (myConnection == null) { MessageBox.Show("OPEN NULL VALUE ====================="); return; } } catch (Exception es) { MessageBox.Show("[Error WITH DB CONNECT...] " + es.Message); } } public bool ExecuteSelectCommand(String selCommand) { try { MessageBox.Show("EXECUTING .. " + selCommand); SqlCommand myCommand = new SqlCommand(selCommand); if (myConnection == null) { MessageBox.Show("NULL VALUE ====================="); return false; } myCommand.Connection = myConnection; myCommand.ExecuteNonQuery(); myReader = myCommand.ExecuteReader(); return true; } public string GetRow() { if (!myReader.Read()) { myReader.Close(); return ""; } int nCol = myReader.FieldCount; string outstr = ""; object[] values = new Object[nCol]; myReader.GetValues(values); for (int i = 0; i < values.Length; i++) { string coldata = values[i].ToString(); coldata = coldata.TrimEnd(); outstr += coldata + ","; } return outstr; }` Client.cs `private void Form1_Load(object sender, EventArgs e) { MessageBox.Show("TEST1"); bool ensureSecurity = true; ChannelServices.RegisterChannel(new TcpClientChannel(), ensureSecurity); dept = (DeptInterface)Activator.GetObject(typeof(DeptInterface), "tcp://KPTEST1:8080/CustServer"); if (dept == null) { MessageBox.Show("TCP SERVER OFFLINE ...PLEASE TRY LATER"); return; } dept.Init(); // Exception Error MessageBox.Show("TEST2"); }` It gives exception at dept.Init() ? What can be the reason please help me... :(
It has been awhile since I've done remoting....but you cannot run a server as a windows form. That is just not right. For a good primer, Ingo Ramer has a great book on remoting that will help you through your problems of creating a great server. Also if you google for remoting you can also find some examples. My services always ran under IIS so that allowed the IIS host to handle all of the connection issues and my classes existed as a service within the web server. However, the long term direction of Microsoft is to eliminate .NET Remoting so if it is at all possible you should move to using WCF instead for you deployment.