c# - Asynchronous Server-Side TCP/IP -
I saw what was necessary in MSDN to create my TCP server, but some parts in the code are missing.
The article and the code here are:
// This server waits for a connection and then uses asynchronous operations // The initial data sent from the customer Accepts connection with // Install the local endpoint for socket IPHostEntreryIfhostInfo = DNSGhatHostEntry (DNSGhatHostname ()); Ipadder ipadder = iphostinfo. Unauthorized list [0]; IPEDpoint localandpoint = new IPPpoint (IPADress, 11000); // Create a TCP / IP socket socket listener = new socket (Address Family.Inter Network, SocketType.Stream, ProtocolType.Tcp); // Tie the socket to the local endpoint, and listen for incoming connections. Listener.Bind (localEndPoint); Listener.Listen (100); While (true) {// set event in non-signal position, allDone.Reset (); // Start the asynchronous socket to listen for connections and get data from clients. Console.light line ("waiting for connection ..."); // Accept the connection and get the first 10 bytes of data. // start acknowledgment () creates an accepted socket Int credentials = 10; Listner. Start accept (blank, received data size, new unbalanced callback (accept residual callback), listener); // Wait until a connection made and processed before continuing. AllDone.WaitOne (); }} Public Static Zero AcceptReceiveDataCallback (IAsyncResult AR) {// Customer sends the request that receives the socket socket listener = (socket) ar.AsyncState; // End the operation and display the data received on the console. Byte [] buffer; Int Bites Transrad; Socket Handler = Listener Accept the end (outside buffer, out-of-the-transfers, AR); String string transferencing = encoding.assici.getstring (buffer, 0, bytes transrad); Console.WriteLine (stringTransferred); Console.light line ("the size of the data is transferred {0}", bytes transferrad); // Create State Objects to Receive asynchronous State object state = new state object (); State.workSocket = Handler; Handler Beneficiaries (state buffer, 0, state object buffer size, 0, new async callback (readclawback), state); } "Event All Dawn" is unavailable, how do I create a similar, so that it will wait for the connection?
There is nothing to do with type events (such as one click event on any control). Both have the word "event" in the name.
See.
Comments
Post a Comment