123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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 IceTcpClientNetSession : 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 = 0;// TCP不侦听端口
- this.mRemoteAddress = IPUtil.ToEndPoint(url_kv[0], int.Parse(url_kv[1]));
- IceClientMessageCodecImpl iceCodec = new IceClientMessageCodecImpl(codec, this);
- iceConnector = new IceTcpClient(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;
- }
- }
- }
|