// 유저 호출 public bool Link(Socket Socket_, SIPPort IPPort_, SKey Key_, TEventHandler RecvEventHandler_, Int32 ConnectTimeOut_) { if (_Socket != null) { return(false); } _RecvEvent = new SocketAsyncEventArgs(); _RecvEvent.Completed += new EventHandler <SocketAsyncEventArgs>(RecvEventHandler_); _SendEvent = new SocketAsyncEventArgs(); _SendEvent.Completed += new EventHandler <SocketAsyncEventArgs>(RecvEventHandler_); _Socket = Socket_; _RecvEvent.UserToken = Key_; _RecvEvent.RemoteEndPoint = IPPort_.EndPoint; _Key = Key_; _LongIP = IPPort_.IP; try { if (!_Socket.ConnectAsync(_RecvEvent)) // _Worker 로 통보받을 필요 없음. { _HBRcvPeriod.NextLoose(); return(_Linked()); } else { _Connecting = true; _ConnectTime = Environment.TickCount; _ConnectTimeOut = ConnectTimeOut_; } } catch { _LinkFailed(); return(false); } return(true); }
public CPeer(Int32 HeaderSize_, TimeSpan HBRcvDelay_, TimeSpan HBSndDelay_, Socket Socket_, CKey Key_, CNamePort NamePort_) { _RecvBuf = new Byte[40960]; _HeaderSize = HeaderSize_; if (HBRcvDelay_.TotalSeconds > 0.0) { _HBRcvPeriod = new CPeriod(HBRcvDelay_ + TimeSpan.FromSeconds(3)); _HBRcvPeriod.NextLoose(); } if (HBSndDelay_.TotalSeconds > 0.0) { _HBSndPeriod = new CPeriod(HBSndDelay_); } _Socket = Socket_; _Key = Key_; _NamePort = NamePort_; }
public bool Poll() { if (!_Socket.Poll(0, SelectMode.SelectRead)) { return(false); } var BytesReceived = _Socket.Receive(_RecvBuf); if (BytesReceived == 0) { throw new ExceptionNet(ENetRet.SocketError); } if (_HBRcvPeriod != null) { _HBRcvPeriod.NextLoose(); } StreamRcv.Push(_RecvBuf, 0, BytesReceived); return(true); }
bool _Sended() { if (_SendEvent.SocketError != SocketError.Success) { _UnLink(ENetState.Normal); return(false); } if (_SendEvent.BytesTransferred == 0) { _UnLink(ENetState.Normal); return(false); } _StreamSnd.PopStream(_SendEvent.BytesTransferred); if (_HBSndPeriod != null) { _HBSndPeriod.NextLoose(); } return(true); }