UCMA4中连接的建立

本文详细介绍使用 UCMA 进行自定义连接流程的具体步骤,包括创建终端、认证终端、会话建立及连接建立的过程,并提供了 C# 代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前文中说到了用UCMASampleHelper帮助建立连接,现在来看自己如何建立。

前文说到了,过程分四步:创建终端、认证终端、会话建立、连接建立。

1.UserEndpoint的构造方法只有一个:

C#代码  收藏代码
  1. public UserEndpoint(CollaborationPlatform platform, UserEndpointSettings settings);  

 第一个参数是平台,第二个是配置。还记得UCMA对象基本都需要配置信息吗?而且一般都是第二个(最后一个)参数。我们先创建UserEndpointSettings的实例,UserEndpointSettings有四个构造方法,我们选择下面这个:

C#代码  收藏代码
  1. public UserEndpointSettings(string ownerUri, string serverName);  

 也就是说“由谁登录,登录到哪”。然后指定它的两个属性:

C#代码  收藏代码
  1. <span style="line-height: 25.200000762939453px;">using System.Net;  
  2. userEndpointSettings.AutomaticPresencePublicationEnabled = true;  
  3. userEndpointSettings.Credential = new NetworkCredential("i""**""ads.assk.com");</span>  

 AutomaticPresencePublicationEnabled设为true 能使对方跟踪你的状态信息。第二个是用来认证的信息,参数分别是用户名、密码、域。

然后来创建平台。CollaborationPlatform有三个构造方法:

C#代码  收藏代码
  1. public CollaborationPlatform(ClientPlatformSettings platformSettings);  
  2. public CollaborationPlatform(ProvisionedApplicationPlatformSettings platformSettings);  
  3. public CollaborationPlatform(ServerPlatformSettings platformSettings);  

 我们传一个ClientPlatformSettings实例:

C#代码  收藏代码
  1. ClientPlatformSettings clientSettings = new ClientPlatformSettings("test", SipTransportType.Tls);  

 SipTransportType有三个枚举值:None,Tcp,Tls。

然后终端就建好了:

C#代码  收藏代码
  1. UserEndpoint endPoint = new UserEndpoint(platform, userEndpointSettings);  

 2.和服务器连接分两步:

C#代码  收藏代码
  1. endPoint.Platform.BeginStartup(CallStarttupComplete, endPoint);  
  2. endPoint.BeginEstablish(CallEstablishCompleted, endPoint);  

 需要用线程信号控制一下,第一个执行完了才能执行第二个。

Java代码  收藏代码
  1. private void CallStarttupComplete(IAsyncResult result)  
  2.         {  
  3.             UserEndpoint userEndPoint = result.AsyncState as UserEndpoint;  
  4.             CollaborationPlatform collabPlatform = userEndPoint.Platform;  
  5.             {  
  6.                 collabPlatform.EndStartup(result);  
  7.             }  
  8.         }  
  9. private void CallEstablishCompleted(IAsyncResult result)  
  10.         {  
  11.             {  
  12.                 UserEndpoint messageCall = result.AsyncState as UserEndpoint;  
  13.                 messageCall.EndEstablish(result);  
  14.                 _callEstablishComplete.Set();  
  15.             }  
  16.         }  

 3.开启会话前一篇文章说了,这里使用一下其他的构造方法:

C#代码  收藏代码
  1. ConversationSettings settings = new ConversationSettings();  
  2. settings.Priority = ConversationPriority.Normal;  
  3. settings.Subject = "Test 01.";  
  4. Conversation conversation = new Conversation(endPoint, settings);  

 4.开始通信的连接建立也提过:

C#代码  收藏代码
  1. InstantMessagingCall imCall = new InstantMessagingCall(conversation);  
  2. imCall.BeginEstablish("sip:i@fd.com"nullnull, CallEstablishCompleted, imCall);  

 建立后才可以继续其他的操作,所以也要在这里用线程暂停。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值