Esempio n. 1
0
        public void Connect(bool runReceiveThreadWhenConnected)
        {
            _queue.Clear();
            if ((_thread != null && _thread.ThreadState == ThreadState.Running) || this.isConnected())
            {
                Disconnect();
            }


            if (_sendType == SendType.Normal)
            {
                //_uSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                base.Connect(_serverIp, _serverPort);

                //_uSocket.Bind(_localEP);
            }
            else if (_sendType == SendType.Multicast)
            {
                base.Connect((IPEndPoint)_remoteEP);
                base.JoinMulticastGroup(NetFunctions.getIP4Address(_serverIp), NetFunctions.getMyIP4Address());

                //_uSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                //_uSocket.Bind(_localEP);
                //_uSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse(server)));
            }
            else //broadcast
            {
                base.Connect((IPEndPoint)_remoteEP);
                base.Client.Bind(_localEP);
                base.Client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.Broadcast, true);
            }

            if (runReceiveThreadWhenConnected)
            {
                runRecvThread();
            }
        }
Esempio n. 2
0
 public void stopUsingReceiveQueue()
 {
     _queue.Clear();
     _isRecvQueueUsing = false;
 }
 public void ClearBuffer()
 {
     _queue.Clear();
     //_isRecvQueueUsing = false;
 }
Esempio n. 4
0
 public void releaseResources()
 {
     _queue.Clear();
 }
Esempio n. 5
0
 public void ReadyForClient()
 {
     _queue.Clear();
     runRecvThread();
 }
Esempio n. 6
0
        public void ReadyForClient()
        {
            _queue.Clear();
            if (_uSocket != null)
            {
                try
                {
                    _uSocket.Close();
                    _queue.Clear();
                }
                catch { }
            }
            if (_thread != null && _thread.ThreadState == ThreadState.Running)
            {
                Thread tt = _thread;
                _thread = null;
                tt.Abort();
            }

            _localEP = new IPEndPoint(IPAddress.Any, _port); //IPAddress.Any 는 서버전용.


            if (_sendType == SendType.Normal)
            {
                try
                {
                    if (_uSocket != null)
                    {
                        _uSocket.Close();
                    }
                }
                catch { }
                _uSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                _uSocket.Bind(_localEP);
            }
            else if (_sendType == SendType.Multicast)
            {
                _uSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                _uSocket.Bind(_localEP);

                _uSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse(_ip)));
                _uSocket.SetSocketOption(SocketOptionLevel.Udp, SocketOptionName.MulticastTimeToLive, 1);
            }
            else //broadcast
            {
                _uSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

                _uSocket.Bind(_localEP);

                _uSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.Broadcast, true);
            }
            if (_readTimeout > 0)
            {
                _uSocket.ReceiveTimeout = _readTimeout;
            }
            if (_writeTimeout > 0)
            {
                _uSocket.SendTimeout = _writeTimeout;
            }

            _remoteEP = new IPEndPoint(IPAddress.None, _port); //this is blank IPEndPoint yet.

            runRecvThread();
        }