RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Fix for binding Socket

Arahil

Sorceror
Fix for binding Socket

This one has also been in the Bugtracker for quite a while now, and i'll post a fix for it here:

The problem is that RunUO does not print an error message if it fails to bind the socket. So it may be that you fail to connect to you server, because another application is using the port, but you are not informed about the socket error.

So here is a possible fix for that - there are more possibilities to do that, but i thought this is the most simple one ;)
Since Listener.Bind(IPAddress, int) returns a Socket object i just check if this returned object is null, which means, that an exception occured in this method. I do this check directly after Listener.Bind(IPAddress, int) is called in Listener..ctor(int)

Code:
public Listener( int port )
{
	m_ThisPort = port;
	m_Disposed = false;
	m_Accepted = new Queue();
	m_OnAccept = new AsyncCallback( OnAccept );

	m_Listener = Bind( IPAddress.Any, port );

	[B]if (m_Listener == null) {
		Console.WriteLine("RunUO failed to bind the Socket. You may not be able to connect to the server");
	} else {[/B]

		try {
			IPHostEntry iphe = Dns.Resolve( Dns.GetHostName() );

			ArrayList list = new ArrayList();
			list.Add( IPAddress.Loopback );

			Console.WriteLine( "Address: {0}:{1}", IPAddress.Loopback, port );

			IPAddress[] ips = iphe.AddressList;

			for ( int i = 0; i < ips.Length; ++i ) {
				if ( !list.Contains( ips[i] ) ) {
					list.Add( ips[i] );

					Console.WriteLine( "Address: {0}:{1}", ips[i], port );
				}
			}
		}
		catch {
		}
	}
}


Considering that Listener.cs provides some of the really, really basic functionality of RunUO the exception handling is way too weak in my opinion.
 

noobie

Wanderer
that is not exception handling, that is debugging..

and i can not see any port number in that debug message ;)
 

Ohms_Law

Wanderer
actually, I disagree. Another app is a possibility, but there's other things that bind ports. bad drivers, power failures, other wierdness. I've seen a problem where every time the server conputer was restarted, the damn NIC wouldn't restart.
Better to get an exception than be in the dark about it.
 

ASayre

RunUO Developer
Actually, something to deal with it not binding to the socket was already put in place for the next version of RunUO atleast a month ago :)
 
Top