Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace IO2
- {
- class Program
- {
- private static byte[] buffer;
- public static object TcpClientclient { get; private set; }
- static void Main(string[] args)
- {
- ThreadPool.QueueUserWorkItem(ServerTCP);
- ThreadPool.QueueUserWorkItem(ClientTCP);
- ThreadPool.QueueUserWorkItem(ClientTCP);
- Thread.Sleep(10000);
- }
- static void ThreadProc(Object stateInfo)
- {
- var integer = (int)stateInfo;
- Thread.Sleep(integer);
- Console.WriteLine(integer);
- }
- static void ServerTCP(object state)
- {
- TcpListener listener = new TcpListener(IPAddress.Any, 8888);
- listener.Start();
- while (true)
- {
- TcpClient client = listener.AcceptTcpClient();
- byte[] odczyt = new byte[1024];
- while (true)
- {
- client.GetStream().Read(odczyt, 0, 1024);
- Console.WriteLine(System.Text.Encoding.ASCII.GetString(odczyt));
- client.GetStream().Write(odczyt, 0, odczyt.Length);
- }
- client.Close();
- }
- }
- static void WriteConsoleMessage(string message, ConsoleColor color)
- {
- Console.ForegroundColor = color;
- Console.WriteLine(message);
- Console.ResetColor();
- }
- static void ClientTCP(object state)
- {
- TcpClient client = new TcpClient();
- client.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8888));
- byte[] message = new ASCIIEncoding().GetBytes("wiadomosc");
- client.GetStream().Write(message, 0, message.Length);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement