Exemplo n.º 1
0
        private bool Send(IPEndPoint remotePoint, NotifyType notifyType, BaseInfo sendInfo)
        {
            try
            {
                byte[] btBuffer = new byte[4 + sendInfo.GetSize()];

                MemoryStream ms = new MemoryStream(btBuffer, true);
                BinaryWriter bw = new BinaryWriter(ms);

                EncodeInteger(bw, (int)notifyType);
                sendInfo.GetBytes(bw);

                bw.Close();
                ms.Close();

                _Sockets[_CurSocketIndex].Send(btBuffer, btBuffer.Length, remotePoint);
            }
            catch (Exception e)
            {
                SetError(ErrorType.Fail_SendSocket, "소켓송신 실패: " + e.Message);
                return(false);
            }

            _CurSocketIndex = (_CurSocketIndex + 1) % _Sockets.Count;

            return(true);
        }
Exemplo n.º 2
0
        public bool Send(NotifyType notifyType, BaseInfo sendInfo)
        {
            try
            {
                // 2014-01-09: GreenRose
                // 재접속을 시도할때 필요한 유저정보를 보관한다.
                if (notifyType == NotifyType.Request_Login)
                {
                    _UserInfo = (UserInfo)sendInfo;
                }

                int sendSize = 4 + sendInfo.GetSize();

                HeaderInfo headerInfo = new HeaderInfo();
                headerInfo._BodySize = sendSize;

                byte[] btBuffer = new byte[headerInfo.GetSize() + sendSize];

                MemoryStream ms = new MemoryStream(btBuffer, true);
                BinaryWriter bw = new BinaryWriter(ms);

                headerInfo.GetBytes(bw);
                EncodeInteger(bw, (int)notifyType);
                sendInfo.GetBytes(bw);

                bw.Close();
                ms.Close();



                _ClientSocket.Send(btBuffer);
            }
            catch (Exception e)
            {
                SetError(ErrorType.Fail_SendSocket, "소켓송신 실패: " + e.ToString());
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        // 2013-12-27: GreenRose
        //public void SocketTimer(object obj, System.Timers.ElapsedEventArgs e)
        //{
        //    if (_listSocketInfo.Count > 0 && _bSendFinished)
        //    {
        //        SendSocketInfo(_listSocketInfo[0].socket, _listSocketInfo[0].notifyType, _listSocketInfo[0].baseInfo);
        //    }
        //}

        // 2013-12-27: GreenRose
        //private bool SendSocketInfo(Socket socket, NotifyType notifyType, BaseInfo sendInfo)
        //{
        //    _bSendFinished = false;

        //    try
        //    {
        //        if (socket.Connected == false)        // auto
        //            return true;

        //        int sendSize = 4 + sendInfo.GetSize();

        //        HeaderInfo headerInfo = new HeaderInfo();
        //        headerInfo._BodySize = sendSize;

        //        byte[] btBuffer = new byte[headerInfo.GetSize() + sendSize];

        //        MemoryStream ms = new MemoryStream(btBuffer, true);
        //        BinaryWriter bw = new BinaryWriter(ms);

        //        headerInfo.GetBytes(bw);
        //        EncodeInteger(bw, (int)notifyType);
        //        sendInfo.GetBytes(bw);

        //        bw.Close();
        //        ms.Close();

        //        socket.Send(btBuffer);

        //        _listSocketInfo.RemoveAt(0);
        //        _bSendFinished = true;
        //    }
        //    catch (Exception e)
        //    {
        //        SetError(ErrorType.Fail_SendSocket, "소켓송신 실패: " + e.Message);
        //        return false;
        //    }

        //    return true;
        //}

        public bool Send(Socket socket, NotifyType notifyType, BaseInfo sendInfo)
        {
            //SocketInfo socketInfo = new SocketInfo();
            //socketInfo.socket = socket;
            //socketInfo.notifyType = notifyType;
            //socketInfo.baseInfo = sendInfo;

            //_listSocketInfo.Add(socketInfo);

            try
            {
                if (socket.Connected == false)        // auto
                {
                    return(true);
                }

                int sendSize = 4 + sendInfo.GetSize();

                HeaderInfo headerInfo = new HeaderInfo();
                headerInfo._BodySize = sendSize;

                byte[] btBuffer = new byte[headerInfo.GetSize() + sendSize];

                MemoryStream ms = new MemoryStream(btBuffer, true);
                BinaryWriter bw = new BinaryWriter(ms);

                headerInfo.GetBytes(bw);
                EncodeInteger(bw, (int)notifyType);
                sendInfo.GetBytes(bw);

                bw.Close();
                ms.Close();

                //int nSendBuffersize = 0;

                //while (nSendBuffersize < btBuffer.Length)
                //{
                //    nSendBuffersize += socket.Send(btBuffer, nSendBuffersize, btBuffer.Length, SocketFlags.None);
                //}
                //if (notifyType == NotifyType.Reply_RoomDetail)
                //{
                //    System.Threading.Thread.Sleep(1000);
                //}

                SocketBuffer socketBuffer = FindBuffer(socket);

                socketBuffer._SendBuffers.Add(btBuffer);

                if (socketBuffer._SendBuffers.Count == 1)
                {
                    SendAsync(socket);
                }

                //System.DateTime dateTime1 = DateTime.Now;
                //byte[] tempBuffer = new byte[100000];
                //for (int i = 0; i < 10; i++)
                //{
                //    int nResult = socket.Send(tempBuffer);
                //    if (nResult != 10000)
                //    {
                //        SetError(ErrorType.Fail_SendSocket, "10000 fail");
                //    }
                //}

                //int nSum = 0;
                //DateTime dateTime2 = DateTime.Now;

                //double nSecond = (dateTime2 - dateTime1).TotalMilliseconds;
            }
            catch (Exception e)
            {
                SetError(ErrorType.Fail_SendSocket, "소켓송신 실패: " + e.Message);
                socket.Shutdown(SocketShutdown.Both);
                socket.Disconnect(true);
                socket.Close();
                _NotifyHandler(NotifyType.Notify_Socket, socket, null);
                return(false);
            }

            return(true);
        }