private TcpChannel CreateChannel(String formatter, NameValueCollection properties, bool createAsServer)
{
TcpChannel tcpChannel = null;
int portNum = GetPort(properties);
bool alreadyRegistered = false;
foreach(IChannel channel in ChannelServices.RegisteredChannels)
{
if (channel.ChannelName.Equals("tcp"))
{
TcpChannel item = (TcpChannel) channel;
ChannelDataStore dataStore = (ChannelDataStore) item.ChannelData;
// TODO: Check if is the same channel as the url specify
tcpChannel = item;
alreadyRegistered = true;
break;
}
}
if (!alreadyRegistered)
{
if (createAsServer)
{
tcpChannel = new TcpChannel(portNum);
}
else
{
tcpChannel = new TcpChannel(0);
}
ChannelServices.RegisterChannel( tcpChannel );
}
return tcpChannel;
}
}