UCMA4中连接的建立

UCMA4初体验中说到了用UCMASampleHelper帮助建立连接,现在来看自己如何建立。

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

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

public UserEndpoint(CollaborationPlatform platform, UserEndpointSettings settings);

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

public UserEndpointSettings(string ownerUri, string serverName);

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

using System.Net;
userEndpointSettings.AutomaticPresencePublicationEnabled = true;
userEndpointSettings.Credential = new NetworkCredential("i", "**", "ads.assk.com");

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

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

public CollaborationPlatform(ClientPlatformSettings platformSettings);
public CollaborationPlatform(ProvisionedApplicationPlatformSettings platformSettings);
public CollaborationPlatform(ServerPlatformSettings platformSettings);

 我们传一个ClientPlatformSettings实例:

ClientPlatformSettings clientSettings = new ClientPlatformSettings("test", SipTransportType.Tls);

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

然后终端就建好了:

UserEndpoint endPoint = new UserEndpoint(platform, userEndpointSettings);

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

endPoint.Platform.BeginStartup(CallStarttupComplete, endPoint);
endPoint.BeginEstablish(CallEstablishCompleted, endPoint);

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

private void CallStarttupComplete(IAsyncResult result)
        {
            UserEndpoint userEndPoint = result.AsyncState as UserEndpoint;
            CollaborationPlatform collabPlatform = userEndPoint.Platform;
            {
                collabPlatform.EndStartup(result);
            }
        }
private void CallEstablishCompleted(IAsyncResult result)
        {
            {
                UserEndpoint messageCall = result.AsyncState as UserEndpoint;
                messageCall.EndEstablish(result);
                _callEstablishComplete.Set();
            }
        }

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

ConversationSettings settings = new ConversationSettings();
settings.Priority = ConversationPriority.Normal;
settings.Subject = "Test 01.";
Conversation conversation = new Conversation(endPoint, settings);

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

InstantMessagingCall imCall = new InstantMessagingCall(conversation);
imCall.BeginEstablish("sip:i@fd.com", null, null, CallEstablishCompleted, imCall);

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值