Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Socket Exception:{"An existing connection was forcibly closed by the remote host"}

Socket Exception:{"An existing connection was forcibly closed by the remote host"}

Scheduled Pinned Locked Moved C#
helpcsharpdatabasesysadminsecurity
11 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H haroon1980

    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... :(

    E Offline
    E Offline
    Ed Poore
    wrote on last edited by
    #2

    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?


    My Blog

    H 1 Reply Last reply
    0
    • E Ed Poore

      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?


      My Blog

      H Offline
      H Offline
      haroon1980
      wrote on last edited by
      #3

      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 :((((

      E 1 Reply Last reply
      0
      • H haroon1980

        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... :(

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #4

        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.

        H 1 Reply Last reply
        0
        • L led mike

          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.

          H Offline
          H Offline
          haroon1980
          wrote on last edited by
          #5

          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; }

          L 1 Reply Last reply
          0
          • H haroon1980

            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; }

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #6

            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.

            H 1 Reply Last reply
            0
            • L led mike

              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.

              H Offline
              H Offline
              haroon1980
              wrote on last edited by
              #7

              so please tell me the way... I will be very thankful to you.

              1 Reply Last reply
              0
              • H haroon1980

                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 :((((

                E Offline
                E Offline
                Ed Poore
                wrote on last edited by
                #8

                Sorry you've exhausted my remoting experience :rolleyes:


                My Blog

                H 1 Reply Last reply
                0
                • E Ed Poore

                  Sorry you've exhausted my remoting experience :rolleyes:


                  My Blog

                  H Offline
                  H Offline
                  haroon1980
                  wrote on last edited by
                  #9

                  this is not fair to me :( anyway if u dont want to help. Its ok

                  E 1 Reply Last reply
                  0
                  • H haroon1980

                    this is not fair to me :( anyway if u dont want to help. Its ok

                    E Offline
                    E Offline
                    Ed Poore
                    wrote on last edited by
                    #10

                    Remember that we are giving up free time to help :|


                    My Blog

                    1 Reply Last reply
                    0
                    • H haroon1980

                      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... :(

                      L Offline
                      L Offline
                      LongRange Shooter
                      wrote on last edited by
                      #11

                      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.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups