本文整理汇总了C#中System.Runtime.Remoting.Channels.Tcp.TcpChannel类的典型用法代码示例。如果您正苦于以下问题:C# TcpChannel类的具体用法?C# TcpChannel怎么用?C# TcpChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TcpChannel类属于System.Runtime.Remoting.Channels.Tcp命名空间,在下文中一共展示了TcpChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Connect
public void Connect()
{
cmbCompression.SelectedIndex = 4;
chan1 = new TcpChannel(8082);
try
{
//Set the Host IP
if(txtServer.Text != "")
hostIP = txtServer.Text;
//Register the TCP Channel
ChannelServices.RegisterChannel(chan1, false);
chan1.StartListening(null);
castTimer.Enabled = true;
connected = true;
btnConnect.ImageIndex = 2;
btnConnect.Text = "Disconnect";
updatePanel(pnlBottom, true);
updateText(lblMessage, "Connected to " + hostIP + " - " + DateTime.Now);
}
catch (Exception exc)
{
updateText(lblMessage, exc.Message);
}
}
示例2: RemotingHostServer
public RemotingHostServer(Machine machine, int port, string name)
: base(machine)
{
this.port = port;
this.name = name;
// TODO review this name, get machine name
this.hostname = "localhost";
// According to http://www.thinktecture.com/resourcearchive/net-remoting-faq/changes2003
// in order to have ObjRef accessible from client code
BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
IDictionary props = new Hashtable();
props["port"] = port;
TcpChannel channel = new TcpChannel(props, clientProv, serverProv);
if (!registered)
{
ChannelServices.RegisterChannel(channel, false);
registered = true;
}
// end of "according"
// TODO review other options to publish an object
this.objref = RemotingServices.Marshal(this, name);
}
示例3: FixtureSetUp
public virtual void FixtureSetUp()
{
lock (lockObject)
{
if (channel == null)
{
try
{
foreach (IChannel registeredChannel in ChannelServices.RegisteredChannels)
{
if (registeredChannel is TcpChannel)
{
((TcpChannel) registeredChannel).StopListening(null);
}
ChannelServices.UnregisterChannel(registeredChannel);
}
channel = new TcpChannel(8005);
#if !NET_2_0
ChannelServices.RegisterChannel(channel);
#else
ChannelServices.RegisterChannel(channel, false);
#endif
}
catch
{
// ignore duplicate registration exception if it occurs...
}
}
}
}
示例4: JoinToChatRoom
private void JoinToChatRoom()
{
if (chan == null && txtName.Text.Trim().Length != 0)
{
chan = new TcpChannel();
ChannelServices.RegisterChannel(chan, false);
// Create an instance of the remote object
objChatWin = new frmChatWin();
objChatWin.remoteObj = (SampleObject)Activator.GetObject(typeof(RemoteBase.SampleObject), txtServerAdd.Text);
if (!objChatWin.remoteObj.JoinToChatRoom(txtName.Text))
{
MessageBox.Show(txtName.Text+ " already joined, please try with different name");
ChannelServices.UnregisterChannel(chan);
chan = null;
objChatWin.Dispose();
return;
}
objChatWin.key = objChatWin.remoteObj.CurrentKeyNo();
objChatWin.yourName= txtName.Text;
this.Hide();
objChatWin.Show();
}
}
示例5: btnStart_Click
private void btnStart_Click(object sender, EventArgs e)
{
setServiceXml();
btnStart.Enabled = false;
try
{
Setting.Load();
BinaryServerFormatterSinkProvider binaryServerFormatterSinkProvider = new BinaryServerFormatterSinkProvider();
BinaryClientFormatterSinkProvider clientSinkProvider = new BinaryClientFormatterSinkProvider();
binaryServerFormatterSinkProvider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary dic = new Dictionary<string, int>();
dic.Add("port", Setting.Instance.Port);
TcpChannel channel = new TcpChannel(dic, clientSinkProvider, binaryServerFormatterSinkProvider);
ChannelServices.RegisterChannel(channel, false);
List<IRemoteService> list = ServicesManager.GetTypeFromAssembly<IRemoteService>();
foreach (IRemoteService service in list)
{
service.RegisterService();
}
btnStop.Enabled = true;
}
catch (Exception ex)
{
btnStart.Enabled = true;
throw ex;
}
}
示例6: PuppetMasterForm
public PuppetMasterForm()
{
InitializeComponent();
//Inicializations
puppet_master_history_TextBox.Text = "";
dump_history_TextBox.Text = "";
command_TextBox.Text = "";
BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = 8400;
props["timeout"] = 200000;
channel = new TcpChannel(props, null, provider);
ChannelServices.RegisterChannel(channel, true);
clients = new Dictionary<string, Tuple<string, ClientInterface>>();
metadataServers = new Dictionary<string, Tuple<string, MetadataServerInterface>>();
dataServers = new Dictionary<string, Tuple<string, DataServerInterface>>();
clientStartPort = 8100;
metadataServerStartPort = 8200;
dataServerStartPort = 8300;
script = null;
}
示例7: Start
public void Start()
{
channel = new TcpChannel(8081);
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(SharedObject), "DataPool", WellKnownObjectMode.Singleton);
Log.Print("Server has started");
}
示例8: RegisterRemoting
private void RegisterRemoting()
{
{
try
{
BinaryServerFormatterSinkProvider server_provider = new BinaryServerFormatterSinkProvider();
server_provider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
BinaryClientFormatterSinkProvider client_provider = new BinaryClientFormatterSinkProvider();
IDictionary properties = new Hashtable();
properties["port"] = "0";
TcpChannel channel = new TcpChannel(properties, client_provider, server_provider);
ChannelServices.RegisterChannel(channel, false);
user = (IUser)Activator.GetObject(typeof(IUser), "tcp://localhost:9998/UserHandeling");
portal = (IPortal)Activator.GetObject(typeof(IPortal), "tcp://localhost:9998/PortalHandeling");
ftserver = (IFTserver)Activator.GetObject(typeof(IFTserver), "tcp://localhost:9998/TransferHandeling");
}
catch (RemotingException e)
{
MessageBox.Show("Connection Error");
}
}
}
示例9: OpenConnection
public void OpenConnection()
{
Log.Info("DatabaseProxy.OpenConnection");
// connecting to the remote database
TcpChannel tcpChannel = new TcpChannel();
ChannelServices.RegisterChannel(tcpChannel);
this.db = (PSPEServer.PSPEDatabaseServer)Activator.GetObject(
typeof(PSPEServer.PSPEDatabaseServer), "tcp://localhost:8085/MyDatabase");
if (null == db)
{
Log.Info("Cannot connect to the server");
}
else
{
Log.Info("Internal tx id:" + db.Connect());
}
// enlisting in the transaction
if (null != this.internalRM)
{
throw new Exception("we don't support multiple connections, this is just a sample");
}
internalRM = new InternalRM(db);
internalRM.Enlist();
}
示例10: Main
static void Main(string[] args)
{
RemotingConfiguration.Configure(@"../../App.config", true);
KeyValuePair<int, int> idAndPort;
System.Console.WriteLine("Bootstrapping...");
TcpChannel channel = new TcpChannel();
ChannelServices.RegisterChannel(channel, false);
System.Console.WriteLine("Registered Channel @random");
string address = System.IO.File.ReadAllText(@"../../../mServerLocation.dat");
MasterInterface mServer = (MasterInterface)Activator.GetObject(typeof(MasterInterface), address);
idAndPort = mServer.RegisterTransactionalServer(getIP());
System.Console.WriteLine("Registered at Master");
ChannelServices.UnregisterChannel(channel);
System.Console.WriteLine("Unbinding old port");
BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel = TypeFilterLevel.Full;
IDictionary props = new Hashtable();
props["port"] = idAndPort.Value;
channel = new TcpChannel(props, null, provider);
ChannelServices.RegisterChannel(channel, false);
System.Console.WriteLine("Registered Channel @" + idAndPort.Value);
TransactionalServer ts = new TransactionalServer(idAndPort.Key, mServer, "tcp://"+getIP()+":"+idAndPort.Value+"/Server");
RemotingServices.Marshal(ts, "Server", typeof(TransactionalServer));
System.Console.WriteLine("SERVER ON");
System.Console.WriteLine("Server: " + idAndPort.Key + " Port: " + idAndPort.Value + " IP: "+ getIP());
System.Console.ReadLine();
}
示例11: Register
//HANDLER DO FORM
public bool Register(string nick, string port)
{
this.nick = nick;
TcpChannel channel = new TcpChannel(Int32.Parse(port));
ChannelServices.RegisterChannel(channel, true);
ObjClient objClient = new ObjClient(formClient);
RemotingServices.Marshal(objClient,
"IChatClient",
typeof(ObjClient));
string serverUrl = "tcp://localhost:8086/IChatServer";
serverObj = (ObjServer)Activator.GetObject(
typeof(ObjServer), serverUrl);
if (serverObj == null) {
System.Console.WriteLine("Could not locate server");
return false;
}
string clientUrl = "tcp://localhost:" + port + "/IChatClient";
serverObj.Register(nick, clientUrl);
return true;
}
示例12: Form1
public Form1()
{
InitializeComponent();
PuppetMaster.ctx = this;
TcpChannel channel = new TcpChannel(8090);
ChannelServices.RegisterChannel(channel, true);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(PuppetMaster), "PseudoNodeReg", WellKnownObjectMode.Singleton);
Clients = new List<Node>();
Servers = new List<Node>();
WriteHostDelegate = new WriteHost(WriteHostMethod);
string currentDirectory = Environment.CurrentDirectory;
string[] newDirectory = Regex.Split(currentDirectory, "PuppetMaster");
string strpath = newDirectory[0] + "Scripts"; //Replace("PuppetMaster", "Scripts");
string[] filePaths = Directory.GetFiles(strpath, "*.txt",
SearchOption.AllDirectories);
foreach (string path in filePaths)
listBox1.Items.Add(path);
this.listBox1.MouseDoubleClick += new MouseEventHandler(listBox1_MouseDoubleClick);
//System.DirectoryServices.DirectoryEntry myDE = new
// System.DirectoryServices.DirectoryEntry(strpath);
//tabPage3.Controls.Add(myDE);
// string nameGuid = myDE.Name + myDE.Guid.ToString();
// WriteUserScriptsDelegate = new WriteUserScripts(WriteUserScriptsMethod);
}
示例13: Main
static void Main(string[] args)
{
RemotingConfiguration.ApplicationName = "CallbackRemoting";
// 设置formatter
BinaryServerFormatterSinkProvider formatter = new BinaryServerFormatterSinkProvider();
formatter.TypeFilterLevel = TypeFilterLevel.Full;
// 设置通道名称和端口
IDictionary propertyDic = new Hashtable();
propertyDic["name"] = "CustomTcpChannel";
propertyDic["port"] = 8502;
// 注册通道
IChannel tcpChnl = new TcpChannel(propertyDic, null, formatter);
ChannelServices.RegisterChannel(tcpChnl, false);
// 注册类型
Type t = typeof(Server);
RemotingConfiguration.RegisterWellKnownServiceType(
t, "ServerActivated", WellKnownObjectMode.Singleton);
Console.WriteLine("Server running, model: Singleton\n");
Console.ReadKey();
}
示例14: Main
public static void Main(string[] args)
{
short port=23456;
Console.WriteLine("USAGE: subserver <portnumber>");
if(args.Length>1 && Int16.TryParse(args[1],out port) && port>1024){
//OK, got good port
} else {
port = 23456; //default port
}
try {
BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
IDictionary props = new Hashtable();
props["port"] = port;
TcpChannel chan = new TcpChannel(props, clientProv, serverProv); //create the tcp channel
ChannelServices.RegisterChannel(chan,false); //register the tcp channel
RemotingConfiguration.RegisterWellKnownServiceType(typeof(subsharelib.subshareRemoteObject),"SUBSERVER",WellKnownObjectMode.Singleton); //publish the remote object
Console.WriteLine("SERVER STARTED AT PORT "+port);
} catch (Exception ex) {
Console.WriteLine("SERVER CAN NOT START! "+ex);
}
Console.Write("Press any key to exit . . . ");
Console.ReadKey(true);
}
示例15: loadRPCServices
private static void loadRPCServices(string[] args)
{
TcpChannel channel;
channel = new TcpChannel(Int32.Parse(args[0]));
ChannelServices.RegisterChannel(channel, true);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ClientToServerServicesObject),
ServicesNames.ClientToServerServicesName,
WellKnownObjectMode.Singleton);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ServerToServerServicesObject),
ServicesNames.ServerToServerServicesName,
WellKnownObjectMode.Singleton);
_myUri = (((ChannelDataStore)channel.ChannelData).ChannelUris)[0];
_primaryURI = _myUri;
_serverPort = args[0];
_ServerToServerServiceObject = (ServerToServerServicesObject)Activator.GetObject(
typeof(ServerToServerServicesObject),
ServerApp._myUri + "/" + ServicesNames.ServerToServerServicesName);
}