BeginAcceptSocket() public méthode

public BeginAcceptSocket ( AsyncCallback callback, object state ) : IAsyncResult
callback AsyncCallback
state object
Résultat IAsyncResult
Exemple #1
0
        static void Main(string[] args)
        {
            GMSKeys.Initialize();

            {
                // Quick test
                ITEMS = new Dictionary<short, ItemEquip>();
                ITEMS.Add(1, new ItemEquip(1113017)
                {
                    StatusFlags = 0x0714,
                    Potential1 = 40356,
                    Potential2 = 30041,
                    Potential3 = 30044,
                    Potential4 = 12011,
                    Potential5 = 2014,
                    Potential6 = 2014,
                    SocketState = 0x00FF,
                    Nebulite2 = 1001,
                    Nebulite1 = 2001,
                    Nebulite3 = 3400,

                });

                //File.WriteAllText("import.xml", ITEMS.Serialize());

                if (File.Exists("import.xml"))
                {
                    ITEMS = File.ReadAllText("import.xml").Deserialize<Dictionary<short, ItemEquip>>();
                }
            }

            if (ITEMS == null)
                ITEMS = new Dictionary<short, ItemEquip>();

            {
                TcpListener listener = new TcpListener(System.Net.IPAddress.Any, 8484);
                listener.Start();

                AsyncCallback EndAccept = null;
                EndAccept = (a) =>
                {
                    new Client(listener.EndAcceptSocket(a));

                    Console.WriteLine("accepted");

                    listener.BeginAcceptSocket(EndAccept, null);
                };

                listener.BeginAcceptSocket(EndAccept, null);
            }



            Console.ReadLine();
        }
Exemple #2
0
        /// <summary>
        /// Constructor used to initialize a new BoggleServer. This will initialize the GameLength
        /// and it will build a dictionary of all of the valid words from the DictionaryPath. If an
        /// optional string was passed to this application, then it will build a BoggleBoard from
        /// the supplied string. Otherwise it will build a BoggleBoard randomly.
        /// </summary>
        /// <param name="GameLength">The length that the Boggle game should take.</param>
        /// <param name="DictionaryPath">The filepath to the dictionary that should be used to
        /// compare words against.</param>
        /// <param name="OptionalString">An optional string to construct a BoggleBoard with.</param>
        public BoggleServer(int GameLength, string DictionaryPath, string OptionalString)
        {
            try
            {
                this.UnderlyingServer = new TcpListener(IPAddress.Any, 2000);
                this.GameLength = GameLength;
                this.DictionaryWords = new HashSet<string>(File.ReadAllLines(DictionaryPath));
                this.WaitingPlayer = null;

                this.CommandReceived = new Object();
                this.ConnectionReceivedLock = new Object();

                if (OptionalString != null)
                    this.OptionalString = OptionalString;

                Console.WriteLine("The Server has Started on Port 2000");

                // Start the server and begin accepting clients.
                UnderlyingServer.Start();
                UnderlyingServer.BeginAcceptSocket(ConnectionReceived, null);

            }

            // If any exception occured when starting the sever or connecting clients,
            // print out an error message and the stacktrace where the error occured.
            catch (Exception e)
            {
                Console.WriteLine("An Exception Occured When Building the BoggleServer:");
                Console.WriteLine(e.ToString());
            }
        }
        public Mainwin()
        {
            
            InitializeComponent();
            cms = this.contextMenuStrip1;  // providing a cms for rows 
            for (int i = 0; i < 21; i++) {
                this.grid1.addRow(); 
            
            }
            Host = SettingsWin.host.Text;
            ports = int.Parse(SettingsWin.Port.Text ) ;

            SettingsWin.resetSocketB.Click += resetSocketB_Click;

            IPAddress ipAd = IPAddress.Parse("127.0.0.1");
            // use local m/c IP address, and 
            // use the same in the client

            /* Initializes the Listener */
            var tempList = new TcpListener(IPAddress.Any, 5202); 
            myList.AddLast(tempList);
            tempList.Start();
           tempList.BeginAcceptSocket(this.AcceptClient,tempList); 
            
            timer1.Start(); 


        }
        void resetSocketB_Click(object sender, EventArgs e)
        {
            foreach (var item in myList)
            {
                item.Stop();
            }
            myList.Clear(); 

            IPAddress ipAd = IPAddress.Parse(SettingsWin.host.Text);
            // use local m/c IP address, and 
            // use the same in the client

            /* Initializes the Listener */


            //TODO : make handle multi listeners  !! 
            String [] a = SettingsWin.Port.Text.Split(','); 
            foreach (String portt in a ) {
                try {

                    var tempList = new TcpListener(IPAddress.Any, int.Parse(portt));
                    tempList.Start(); 
                    tempList.BeginAcceptSocket(this.AcceptClient, tempList);
                    myList.AddLast(tempList); 
                }
                catch { 
                }
            }
              

            
        }
Exemple #5
0
 public void StartListener(string ip,int port)
 {
     socket = new Socket(SocketType.Stream,ProtocolType.Tcp);
     listener = new TcpListener(new IPEndPoint(IPAddress.Parse(ip), port));
     listener.Start();
     listener.BeginAcceptSocket(clientConnect, listener);
 }
Exemple #6
0
        /// <summary>
        /// Constructor to create the list of connects and create
        /// a new thread to wait/accept new connections
        /// </summary>
        public ConnectionManager(String host, String p)
        {
            Log.WriteMessage("WhitStream Server Started.", Log.eMessageType.Normal);
            m_ipAddress = IPAddress.Parse(host);
            m_listenPort = int.Parse(p);

            //Initialize the list to hold no connections and default capacity
            m_connectionList = new List<Connection>();

            //Initialize the list to hold all ports from 4001 to 4010
            m_availablePorts = new Queue<int>(10);
            for (int i = 4001; i <= 4010; i++)
            {
                m_availablePorts.Enqueue(i);
            }

            Log.WriteMessage("Waiting for connections....", Log.eMessageType.Debug);

            //Register a new TcpListener
            m_incomingListener = new TcpListener(m_ipAddress, m_listenPort);
            m_incomingListener.Start();
            m_incomingListener.BeginAcceptSocket(new AsyncCallback(Accept_Socket), null);

            m_checkThread = new Thread(CheckConnections);
            m_checkThread.Start();
        }
        /// <summary>
        /// Creates a new NPCServer
        /// </summary>
        internal Framework(string OptionsFile = "settings.ini")
        {
            // Default PM
            this.NCMsg = CString.tokenize ("I am the npcserver for\nthis game server. Almost\nall npc actions are controled\nby me.");

            // Create Compiler
            Compiler = new GameCompiler (this);

            // Create Player Manager
            PlayerManager = new Players.PlayerList (this, GSConn);
            AppSettings settings = AppSettings.GetInstance ();
            settings.Load (OptionsFile);

            // Connect to GServer
            GSConn = new GServerConnection (this);

            this.ConnectToGServer();

            // Setup NPC-Control Listener
            cNCAccept = new AsyncCallback (NCControl_Accept);
            this.UPnPOpenPort();
            NCListen = new TcpListener (IPAddress.Parse (this.LocalIPAddress ()), settings.NCPort);
            NCListen.Start ();
            NCListen.BeginAcceptSocket (cNCAccept, NCListen);

            settings.Save ();

            // Setup Timer
            //timeBeginPeriod(50);
            //TimerHandle = new TimerEventHandler(RunServer);
            //TimerId = timeSetEvent(50, 0, TimerHandle, IntPtr.Zero, EVENT_TYPE);
        }
Exemple #8
0
        /// <summary>
        /// Creates a BoggleServer that listens for connections on port 2000.
        /// </summary>
        public BoggleServer(int gameTime, HashSet<string> dictionary, string boardConfiguration)
        {
            // Initialize fields.
            _PORT = 2000;
            _server = new TcpListener(IPAddress.Any, _PORT);
            _waitingPlayer = null;
            _allMatches = new HashSet<Match>();
            _lock = new object();
            _gameTime = gameTime;
            _dictionary = dictionary;
            _boardConfiguration = boardConfiguration;

            // Start the server.
            _server.Start();

            // Start listening for a client to connect.
            _server.BeginAcceptSocket(ConnectionReceived, null);

            // Create a timer with a one second interval.
            timer = new System.Timers.Timer(1000);

            // Hook up the Elapsed event for the timer. 
            timer.Elapsed += OneSecondHasPassed;
            timer.Enabled = true;

            // Keep this program alive
            Thread t = new Thread(stayAlive);
            t.Start();
        }
Exemple #9
0
        private Connect4ClientConnection waiting; //Player 1 - put into a game as soon as Player 2 is identified. Set to null once the game starts

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructs a new Connect4Service object. Takes values to set the port it listens on,
        /// as well as a time limit for games held on this server.
        /// Throws InvalidOperationException if timelimit &lt; 1, or the port number is out of range
        /// or already being listened on.
        /// </summary>
        /// <param name="portNumber">Port for the server to listen on</param>
        /// <param name="timeLimit">Time limit for users in games on this server</param>
        public Connect4Service(int portNumber, int _timeLimit, WhoGoesFirst _choosingMethod)
        {
            if (_timeLimit <= 0)
            {
                throw new InvalidOperationException("time limit must be positive");
            }
            if (portNumber > IPEndPoint.MaxPort || portNumber < IPEndPoint.MinPort)
            {
                throw new InvalidOperationException("invalid port number");
            }
            choosingMethod = _choosingMethod;
            games = new List<Connect4Game>();
            needToIdentify = new List<Connect4ClientConnection>();
            waiting = null;
            timeLimit = _timeLimit;
            server = new TcpListener(IPAddress.Any, portNumber);
            try
            {
                server.Start();
            }
            catch (SocketException)
            {
                throw new InvalidOperationException("port already taken (or something like that)");
            }

            server.BeginAcceptSocket(ConnectionRequested, null);
            isShuttingDown = false;
        }
 //----------------------------------------------------------------------
 //Construction, Destruction
 //----------------------------------------------------------------------
 /// <summary>
 /// Creating server socket
 /// </summary>
 /// <param name="port">Server port number</param>
 public StandardTcpServer(int port)
 {
     connectedSockets = new Dictionary<IPEndPoint, Socket>();
     tcpServer = new TcpListener(IPAddress.Any, port);
     tcpServer.Start();
     tcpServer.BeginAcceptSocket(EndAcceptSocket, tcpServer);
 }
Exemple #11
0
 public void Start()
 {
     _stop = false;
     _listener = new TcpListener(IPAddress.Any, _port);
     _listener.Start();
     _listener.BeginAcceptSocket(OnAcceptSocket, null);
 }
Exemple #12
0
 public void Start(int port)
 {
     if (RequestHandler == null)
         throw new InvalidOperationException("You must hook the RequestHandler delegate first.");
     _listener = new TcpListener(IPAddress.Any, port);
     _listener.Start(500);
     _listener.BeginAcceptSocket(OnAccept, null);
 }
Exemple #13
0
        public netservice()
        {
            listen = new TcpListener(IPAddress.Parse("0.0.0.0"), 1234);

            listen.Start();

            listen.BeginAcceptSocket(new AsyncCallback(this.onAccept), listen);
        }
Exemple #14
0
		internal bool Start(ushort port) {
			if (Running) { throw new Exception("Listener is already running."); }
			listen = new TcpListener(IPAddress.Any,port);
			try { listen.Start(); }
			catch { Stop(); return false; }
			listen.BeginAcceptSocket(new AsyncCallback(Accept),null);
			return true;
		}
Exemple #15
0
 /// <summary>
 /// #ctor
 /// makes server with new client lis
 /// </summary>
 /// <param name="port"></param>
 public BoggleServer(int port)
 {
     server = new TcpListener(IPAddress.Any,port);
     clients = new Queue<Tuple<StringSocket, string>>();
     currentGames = new HashSet<game>();
     server.Start();
     server.BeginAcceptSocket(ConnectionAccept, null);
 }
		public override void StartProcessing()
		{
			_options.Validate();

			_listener = new TcpListener(_options.Endpoint);
			_listener.Start();
			_listener.BeginAcceptSocket(AcceptCallback, _listener);
		}
Exemple #17
0
 public MainWindow()
 {
     InitializeComponent();
     FS = new FileStream("C:\\Users\\CORE\\Desktop\\vidTEST",FileMode.Create,FileAccess.Write);
     receiveBytes = new byte[1000000];
     listener = new TcpListener(IPAddress.Any, serverPort);
     listener.Start();
     listener.BeginAcceptSocket(acceptClient, null);
 }
        /// <summary>
        /// Starts listening for incoming connections at ::1 on a random port.
        /// </summary>
        public void Listen()
        {
            _server = new TcpListener(IPAddress.IPv6Loopback, 0);
            _server.Start();
            _server.BeginAcceptSocket(AcceptClient, null);

            _timeout = new Thread(Timeout);
            _timeout.Start();
        }
Exemple #19
0
        public GlowListener(int port, int maxPackageLength)
        {
            Port = port;
             MaxPackageLength = maxPackageLength;

             _listener = new TcpListener(IPAddress.Any, port);
             _listener.Start();
             _listener.BeginAcceptSocket(Callback_Accept, _listener);
        }
        public TcpServer(int port)
        {
            Contract.Requires(0 <= port && port <= ushort.MaxValue);

            socketsDictionary = new Dictionary<IPEndPoint, Socket>();
            tcpServer = new TcpListener(IPAddress.Any, port);
            tcpServer.Start();
            tcpServer.BeginAcceptSocket(EndAcceptSocket, tcpServer);
        }
        public Listener(IPAddress address, int port)
        {
            listener = new TcpListener (address, port);
            uri = new Uri (string.Format ("http://{0}:{1}/", address, port));
            handlers = new Dictionary<string, Handler> ();
            listener.Start ();

            listener.BeginAcceptSocket (AcceptSocketCB, null);
        }
Exemple #22
0
        public acceptnetworkservice(String ip, short port, juggle.process _process)
        {
            process_ = _process;

            listen = new TcpListener(IPAddress.Parse(ip), port);

            listen.Start();

            listen.BeginAcceptSocket(new AsyncCallback(this.onAccept), listen);
        }
 public static TestConnection CreateConnection()
 {
     var listener = new TcpListener(IPAddress.Loopback, 0);
     listener.Start();
     var ar = listener.BeginAcceptSocket(null, null);
     var s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     s.Connect(IPAddress.Loopback, ((IPEndPoint) listener.LocalEndpoint).Port);
     var server = listener.EndAcceptSocket(ar);
     return new TestConnection {Client = s, Server = server};
 }
Exemple #24
0
 static Tuple<int, IDisposable> ListenTcp(AsyncCallback accept)
 {
     var socket = new TcpListener (IPAddress.Loopback, 0);
     socket.Start ();
     socket.BeginAcceptSocket (accept, socket);
     var endpoint = socket.LocalEndpoint as IPEndPoint;
     if (endpoint == null)
         Assert.Fail ("LocalEndPoint wasn't an IPEndPoint");
     return new Tuple<int,IDisposable>(endpoint.Port, socket.Server);
 }
Exemple #25
0
        /// <summary>
        /// Constructs a new web server.
        /// </summary>
        public WebServer()
        {
            Console.WriteLine("Web Server started.");

            // Start the server, and listen for incoming connections.
            server = new TcpListener(IPAddress.Any, 2500);
            server.Start();
            server.BeginAcceptSocket(ConnectionReceived, null);
            sendString.Append("<html>");
        }
 public GwTcpListener(Gateway gateway, ChainSide side, IPEndPoint ipSource)
 {
     this.gateway = gateway;
     this.ipSource = ipSource;
     this.side = side;
     tcpListener = new TcpListener(ipSource);
     tcpListener.Start(10);
     tcpListener.BeginAcceptSocket(ReceiveConn, tcpListener);
     if (Log.WillDisplay(System.Diagnostics.TraceEventType.Start))
         Log.TraceEvent(System.Diagnostics.TraceEventType.Start, -1, "TCP Listener " + side.ToString() + " on " + ipSource);
 }
Exemple #27
0
        private void Run(string[] args)
        {
            int port = Int32.Parse(args[0]);
            Console.WriteLine("Started listening on port: {0}", port);
            var server = new TcpListener(IPAddress.Any, port);
            server.Start();
            server.BeginAcceptSocket(new AsyncCallback(server_onAccept), server);

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Exemple #28
0
        public Socket GetConnectedSocket()
        {
            var listener = new TcpListener(IPAddress.Loopback, 0);
            listener.Start();
            IAsyncResult res = listener.BeginAcceptSocket(null, null);
            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _socket.Connect(IPAddress.Loopback, listener.LocalEndpoint.As<IPEndPoint>().Port);
            Socket clientSocket = listener.EndAcceptSocket(res);

            StartRead();
            return clientSocket;
        }
Exemple #29
0
        static void Main(string[] args)
        {
            TcpListener listen = new TcpListener( IPAddress.Any, 8023);
            listen.Start();

            while (true)
            {
                clientConnected.Reset();
                listen.BeginAcceptSocket(OnAccept, listen);
                clientConnected.WaitOne();
            }
        }
Exemple #30
0
        /// <summary>
        /// Constructs a new boggle server.
        /// </summary>
        public Server(int port)
        {
            server = new TcpListener(IPAddress.Any, port);
            server.Start();
            server.BeginAcceptSocket(ConnectionReceived, null);

            // Initialize the new Queue.
            User = new Queue<User>();

            //Initialize the new Lobby
            lobby = new Lobby();
        }
 void AcceptCallback(IAsyncResult ar)
 {
     try {
         if (!IsTerminating)
         {
             Socket clientSocket = serverSocket.EndAcceptSocket(ar);
             clientSocketList.Add(clientSocket.GetHashCode().ToString(), clientSocket);
             clientSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), clientSocket);
             serverSocket.BeginAcceptSocket(new AsyncCallback(AcceptCallback), null);
         }
     } catch (Exception ex) {
     }
 }
        public bool Initialize(IHost hostApplication)
        {
            My = hostApplication;
            FeuerwehrCloud.Helper.Logger.WriteLine("|  *** BosMon-Compatibility loaded: listening on Port 3334");
            try {
                serverSocket = new TcpListener(IPAddress.Any, 3334);

                serverSocket.Start();
                serverSocket.BeginAcceptSocket(new AsyncCallback(AcceptCallback), null);
            } catch (Exception ex) {
            }


            return(true);
        }
Exemple #33
0
        public void Start()
        {
            if (CreateLogs)
            {
                logFile           = new System.IO.StreamWriter(LogsPath, true);
                logFile.AutoFlush = true;
            }
            if (CreateLogs)
            {
                logFile.WriteLine("S\t" + DateTime.Now.ToString()); logFile.Flush();
            }
            listener.Start(int.MaxValue);
            if (RootAddress == null || RootAddress == "")
            {
                throw new ArgumentNullException("rootAddress", "Null value");
            }

            if (!(new System.IO.DirectoryInfo(RootAddress)).Exists)
            {
                throw new ArgumentNullException("rootAddress", "Invalid value");
            }

            listener.BeginAcceptSocket(ConnectionHandler, listener);
        }
Exemple #34
0
        /// <summary>
        /// Starts the TCP server and begin to listen incomming connections
        /// </summary>
        public void Start()
        {
            if (running)
            {
                throw new Exception("Tcp Server already running");
            }
            if (port <= 0)
            {
                throw new Exception("Port is not configured");
            }
            //listener = new TcpListener(IPAddress.Parse("127.0.0.1"), port);
            listener = new TcpListener(IPAddress.Any, port);
            //listener.ExclusiveAddressUse

            listener.Server.ReceiveBufferSize = this.bufferSize;
            listener.Server.SendBufferSize    = this.bufferSize;
            listener.Start();
            listener.BeginAcceptSocket(dlgSocketAccepted, listener);
            running = true;
        }
Exemple #35
0
        private void SocketAccepted(IAsyncResult result)
        {
            Socket           s;
            AsyncStateObject aso;

            try
            {
                s = listener.EndAcceptSocket(result);
            }
            catch { return; }

            if (s.Connected)
            {
                clients.Add(s);
                aso = new AsyncStateObject(s, bufferSize);
                BeginReceive(aso);
                if (ClientConnected != null)
                {
                    ClientConnected(s);
                }
            }
            listener.BeginAcceptSocket(dlgSocketAccepted, listener);
        }