コード例 #1
0
        public void setServerInfo(string server, int port, Boolean isUsingReceiveQueue = true, FileStream saveFile = null, int readTimeout = 0, int writeTimeout = 0)
        {
            //_localEP = new IPEndPoint(IPAddress.Any, port); //IPAddress.Any 는 서버전용.
            _isEndConnection = false;
            _localEP         = new IPEndPoint(NetFunctions.getMyIP4Address(), IPEndPoint.MinPort + 1); //this is blank IPEndPoint yet.
            _readTimeout     = readTimeout;
            _writeTimeout    = writeTimeout;
            _serverIp        = server;
            _serverPort      = port;
            //_localEP = new IPEndPoint(IPAddress.None, port); //this is blank IPEndPoint yet.

            if (server != null && server.Length > 7)
            {
                _remoteEP = new IPEndPoint(NetFunctions.getIP4Address(_serverIp), _serverPort);
            }
            else
            {
                _remoteEP = new IPEndPoint(NetFunctions.getMyIP4Address(), _serverPort);
            }
            if (_uSocket != null)
            {
                try
                {
                    _uSocket.Close();
                }
                catch { }
            }



            useReceiveQueue(saveFile); //udp는 무조건 queue를 쓴다.


            //            setServer(server, port, null, readTimeout, writeTimeout);
        }
コード例 #2
0
        /// <summary>
        /// 서버의 정보를 적는다.
        /// 바로 받는 루틴을 시작하지는 않는다.
        /// </summary>
        /// <param name="server"></param>
        /// <param name="port"></param>
        /// <param name="isUsingReceiveQueue"></param>
        /// <param name="saveFile"></param>
        /// <param name="readTimeout"></param>
        /// <param name="writeTimeout"></param>
        public void setServerInfo(string server, int port, Boolean isUsingReceiveQueue = false, FileStream saveFile = null, int readTimeout = 0, int writeTimeout = 0)
        {
            if (_listener != null)
            {
                return;
            }

            _isEndServer = false;

            IPEndPoint ipe;

            if (server != null && server.Length > 7)
            {
                ipe = new IPEndPoint(NetFunctions.getIP4Address(server), port);
            }
            else
            {
                ipe = new IPEndPoint(NetFunctions.getMyIP4Address(), port);
            }
            _listener = new TcpListener(ipe);
            _listener.Start();
            if (isUsingReceiveQueue)
            {
                useReceiveQueue(saveFile);
            }
            _readTimeout  = readTimeout;
            _writeTimeout = writeTimeout;


            //            setServer(server, port, null, readTimeout, writeTimeout);
        }
コード例 #3
0
        /// <summary>
        /// 서버의 정보를 적는다.
        /// 바로 받는 루틴을 시작하지는 않는다.
        /// </summary>
        /// <param name="server"></param>
        /// <param name="port"></param>
        /// <param name="isUsingReceiveQueue"></param>
        /// <param name="saveFile"></param>
        /// <param name="readTimeout"></param>
        /// <param name="writeTimeout"></param>
        public void setServerInfo(string server, int port, int readTimeout = 0, int writeTimeout = 0)
        {
            if (_listener != null)
            {
                return;
            }

            _isEndServer = false;

            IPEndPoint ipe;

            if (server != null && server.Length > 7)
            {
                ipe = new IPEndPoint(NetFunctions.getIP4Address(server), port);
            }
            else
            {
                ipe = new IPEndPoint(NetFunctions.getMyIP4Address(), port);
            }
            _listener = new TcpListener(ipe);
            _listener.Start();

            _readTimeout  = readTimeout;
            _writeTimeout = writeTimeout;


            //            setServer(server, port, null, readTimeout, writeTimeout);
        }
コード例 #4
0
        public void ConnectToServer(bool startRecvWhenConnected)
        {
            if ((_thread != null && _thread.ThreadState == ThreadState.Running) || this.isConnected())
            {
                close();
            }

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

                _uSocket = _client.Client;

                //_uSocket.Bind(_localEP);
            }
            else if (_sendType == SendType.Multicast)
            {
                _client = new UdpClient();//server, port);
                _client.Connect((IPEndPoint)_remoteEP);
                _uSocket = _client.Client;
                _client.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
            {
                _client = new UdpClient();
                _client.Connect((IPEndPoint)_remoteEP);
                _uSocket = _client.Client;// new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                _uSocket.Bind(_localEP);
                _uSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.Broadcast, true);
            }

            if (startRecvWhenConnected)
            {
                runRecvThread();
            }
        }
コード例 #5
0
        public void setServerInfo(string server, int port, int readTimeout = 0, int writeTimeout = 0)
        {
            _readTimeout  = readTimeout;
            _writeTimeout = writeTimeout;
            _serverIp     = server;
            _serverPort   = port;

            _isEndConnection = false;
            _localEP         = new IPEndPoint(NetFunctions.getMyIP4Address(), IPEndPoint.MinPort + 1); //this is blank IPEndPoint yet.
            //_localEP = new IPEndPoint(IPAddress.None, port); //this is blank IPEndPoint yet.

            if (server != null && server.Length > 7)
            {
                _remoteEP = new IPEndPoint(NetFunctions.getIP4Address(_serverIp), _serverPort);
            }
            else
            {
                _remoteEP = new IPEndPoint(NetFunctions.getMyIP4Address(), _serverPort);
            }


            //            setServer(server, port, null, readTimeout, writeTimeout);
        }
コード例 #6
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();
            }
        }
コード例 #7
0
        public void setServer(string server, int port, Boolean isUsingReceiveQueue = true, FileStream saveFile = null, int readTimeout = 0, int writeTimeout = 0)
        {
            //_localEP = new IPEndPoint(IPAddress.Any, port); //IPAddress.Any 는 서버전용.
            _readTimeout  = readTimeout;
            _writeTimeout = writeTimeout;
            _serverIp     = server;
            _serverPort   = port;

            _isEndConnection = false;
            _localEP         = new IPEndPoint(NetFunctions.getMyIP4Address(), IPEndPoint.MinPort + 1); //this is blank IPEndPoint yet.
            //_localEP = new IPEndPoint(IPAddress.None, port); //this is blank IPEndPoint yet.

            if (server != null && server.Length > 7)
            {
                _remoteEP = new IPEndPoint(NetFunctions.getIP4Address(_serverIp), _serverPort);
            }
            else
            {
                _remoteEP = new IPEndPoint(NetFunctions.getMyIP4Address(), _serverPort);
            }
            if (_uSocket != null)
            {
                try
                {
                    _uSocket.Close();
                }
                catch { }
            }

            if (_sendType == SendType.Normal)
            {
                //_uSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                _client = new UdpClient(server, port);
                _client.Connect((IPEndPoint)_remoteEP);

                _uSocket = _client.Client;

                //_uSocket.Bind(_localEP);
            }
            else if (_sendType == SendType.Multicast)
            {
                _client  = new UdpClient(server, port);
                _uSocket = _client.Client;
                _client.Connect((IPEndPoint)_remoteEP);
                _client.JoinMulticastGroup(NetFunctions.getIP4Address(server), 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
            {
                _uSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                _uSocket.Bind(_localEP);
                _uSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.Broadcast, true);
            }



            useReceiveQueue(saveFile); //udp는 무조건 queue를 쓴다.

            runRecvThread();
//            setServer(server, port, null, readTimeout, writeTimeout);
        }