1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using CommonNetwork_ICE.Util;
- using CommonLang.Protocol;
- using CommonNetwork_ICE.Common;
- using Slice;
- using CommonNetwork_ICE.Client;
- using CommonNetwork.Net;
- using System.Collections;
- using CommonLang.IO;
- using CommonLang.Log;
- using CommonLang.Net;
- namespace CommonNetwork_ICE.Session
- {
- /// <summary>
- /// 网络会话对象实现,通过会话对象可以发送消息,存储会话级变量
- /// </summary>
- public class IceUdpClientNetSession : IceClientNetSession
- {
- public override bool Open(string url, INetPackageCodec codec, INetSessionListener listener)
- {
- if(IsConnected)
- {
- return true;
- }
- bool ret = false;
- try
- {
- lock (this)
- {
- this.mListener = listener;
- this.mCodec = codec;
- string[] url_kv = url.Split(':');
- this.mHost = url_kv[0];
- this.mPort = int.Parse(url_kv[1]);
- int localListenPort = int.Parse(url_kv[2]);
- this.mRemoteAddress = IPUtil.ToEndPoint(url_kv[0], int.Parse(url_kv[1]));
- IceClientMessageCodecImpl iceCodec = new IceClientMessageCodecImpl(codec, this);
- iceConnector = new IceUdpClient(this, url_kv[0], this.mPort);
- iceConnector.SetMessageCodec(iceCodec);
- iceConnector.Open(localListenPort);
-
- ret = true;
- onOpen();
- }
- }
- catch (Exception err)
- {
- onException(new NetException("Open: " + url + " Exception " + err.Message));
- }
- return ret;
- }
- }
- }
|