本文整理匯總了C#中System.Runtime.Remoting.Channels.IChannelReceiver接口的典型用法代碼示例。如果您正苦於以下問題:C# IChannelReceiver接口的具體用法?C# IChannelReceiver怎麽用?C# IChannelReceiver使用的例子?那麽, 這裏精選的接口代碼示例或許可以為您提供幫助。
IChannelReceiver接口屬於System.Runtime.Remoting.Channels命名空間,在下文中一共展示了IChannelReceiver接口的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: MyCustomChannel
class MyCustomChannel : IChannelReceiver
{
private ChannelDataStore myChannelData;
private int myChannelPriority = 25;
// Set the 'ChannelName' to 'MyCustomChannel'.
private string myChanneName = "tcp";
// Implement 'ChannelName' property.
private TcpListener myTcpListener;
private int myPortNo;
private bool myListening = false;
private Thread myThread;
public MyCustomChannel(int portNo)
{
myPortNo = portNo;
string [] myURI = new string[1];
myURI[0] = Dns.Resolve(Dns.GetHostName()).AddressList[0] + ":" +
portNo.ToString();
// Store the 'URI' in 'myChannelDataStore'.
myChannelData = new ChannelDataStore(myURI);
// Create 'myTcpListener' to listen at the 'myPortNo' port.
myTcpListener = new TcpListener(myPortNo);
// Create the thread 'myThread'.
myThread = new Thread(new ThreadStart(myTcpListener.Start));
this.StartListening(null);
}
public string ChannelName
{
get
{
return myChanneName;
}
}
public int ChannelPriority
{
get
{
return myChannelPriority;
}
}
public string Parse(string myUrl, out string objectURI)
{
Regex myRegex = new Regex("/",RegexOptions.RightToLeft);
// Check for '/' in 'myUrl' from Right to left.
Match myMatch = myRegex.Match(myUrl);
// Get the object URI.
objectURI = myUrl.Substring(myMatch.Index);
// Return the channel url.
return myUrl.Substring(0,myMatch.Index);
}
// Implementation of 'IChannelReceiver' interface.
public object ChannelData
{
get
{
return myChannelData;
}
}
// Create and send the object URL.
public string[] GetUrlsForUri(string objectURI)
{
string[] myString = new string[1];
myString[0] = Dns.Resolve(Dns.GetHostName()).AddressList[0]
+ "/" + objectURI;
return myString;
}
// Start listening to the port.
public void StartListening(object data)
{
if(myListening == false)
{
myTcpListener.Start();
myListening = true;
Console.WriteLine("Server Started Listening !!!");
}
}
// Stop listening to the port.
public void StopListening(object data)
{
if(myListening == true)
{
myTcpListener.Stop();
myListening = false;
Console.WriteLine("Server Stopped Listening !!!");
}
}
}