Failed to read data from transport connection: connection was closed

An exception is Remoting Exception - Authentication Failure. A detailed message says: "Unable to read data from transport connection: connection was closed."

I am having problems creating two simple servers that can communicate as remote objects in C #. ServerInfo is just the class that I created that contains IP and port and can return an address. It works great since I used it before and I debugged it. Also, the server starts just fine, no exception is thrown, and the channel is registered without problems. I use Forms to execute interfaces and call some of the methods on the server, but I did not find any problems with passing parameters from FormsApplication to the server during debugging. In this chapter, everything seems beautiful.

public ChordServerProgram() { RemotingServices.Marshal(this, "PADIBook"); nodeInt = 0; } public void startServer() { try { serverChannel = new TcpChannel(serverInfo.Port); ChannelServices.RegisterChannel(serverChannel, true); } catch (Exception e) { Console.WriteLine(e.ToString()); } } 

I run two instances of this program. Then startNode is called in one of the application instances. The port is in order, the generated address is also beautiful. As you can see, I am using IP for localhost, as this server is for testing only.

 public void startNode(String portStr) { IPAddress address = IPAddress.Parse("127.0.0.1"); Int32 port = Int32.Parse(portStr); serverInfo = new ServerInfo(address, port); startServer(); //node = new ChordNode(serverInfo,this); } 

Then, in another case, through the interface again, I call another startNode method, providing it with a start server for information. Everything is going wrong here. When he calls the method on the seedServer proxy, he just got a RemotingException due to an authentication failure. (The parameter I want to get is node, I just use int to make sure the ChordNode class has nothing to do with this error.)

  public void startNode(String portStr, String seedStr) { IPAddress address = IPAddress.Parse("127.0.0.1"); Int32 port = Int32.Parse(portStr); serverInfo = new ServerInfo(address, port); IPAddress addressSeed = IPAddress.Parse("127.0.0.1"); Int32 portSeed = Int32.Parse(seedStr); ServerInfo seedInfo = new ServerInfo(addressSeed, portSeed); startServer(); ChordServerProgram seedServer = (ChordServerProgram)Activator.GetObject(typeof(ChordServerProgram), seedInfo.GetFullAddress()); // node = new ChordNode(serverInfo,this); int seedNode = seedServer.nodeInt; // node.chordJoin(seedNode.self); } 
+4
source share
2 answers

Try setting securitySecurity to false and it should start working.

ChannelServices.RegisterChannel(serverChannel, false);

0
source

You indicated that security is required for your Remoting server in startServer () with:

 ChannelServices.RegisterChannel(serverChannel, true); 

However, at the end of the "client" security is not indicated, which means an authorization error. You need to specify tcp channel protection at both ends if the server security parameter is set to false. In your second startNode method, you need to perform the following steps before using Activator.GetObject, do not mark the port specified in TcpChannel, unlike the server end:

 TcpChannel ClientChan = new TcpChannel(); ChannelServices.RegisterChannel(ClientChan, true); 

In addition, if you do not do this in some code that you did not give us, you also do not seem to have registered the known server side of the service type, although you say that it works in the debugger, so this may not be necessary in case . See MSDN at RegisterWellKnownServiceType .

0
source

Source: https://habr.com/ru/post/1310351/


All Articles