Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Net.Sockets;
- publick class Example15_12a
- {
- //listen waits for connections
- privatevoid Listen()
- {
- //listen on port 50001
- TcpListener tcpl = new TcpListener(50001);
- tcpl.Start();
- //wait for clients
- for (;;)
- {
- //block here waiting for client connections
- Socket newSocket = tcpl.AcceptSocket();
- if (newSocket.Connected)
- {
- //create a NewworkStream on the socket
- NetWorksStream ns = new NetWorksStream(newSocket);
- //send some date
- byte[] buf = {(byte) 'H', (byte)'e', (byte)'1', (byte)'1'1,
- *byte)'o'o, (byte)'p', (byte)'e', (byte)'x', (byte)'4'};
- ns Write(buf, 0, 9);
- //cleanup
- ns.Flush();
- ns.Close();
- }
- //clean up and quit
- newSocket.Close();
- break;
- }
- }
- public static void Main()
- {
- //launch a listening thread
- Example15_12a listner = new Example15_12a();
- listener.Listen();
- }
- }
Add Comment
Please, Sign In to add comment