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.Text;
- using System.Threading.Tasks;
- using System.Net.Sockets;
- using System.Net;
- namespace Serwer
- {///////////////////////////////////// S E R W E R //////////////
- class Program
- {
- private static TcpListener tcpLsn;
- private static Socket s;
- private static void slij(string mess)
- {
- Byte[] byteData = Encoding.ASCII.GetBytes(mess.ToCharArray());
- s.Send(byteData, byteData.Length, 0);
- }
- static void serwuj()
- {
- tcpLsn = new TcpListener(IPAddress.Parse("127.0.0.1"), 2222);
- tcpLsn.Start();
- Socket sckt = tcpLsn.AcceptSocket();
- Byte[] odebraneBajty = new Byte[100];
- int ret = sckt.Receive(odebraneBajty, odebraneBajty.Length, 0);
- string tmp = null;
- tmp = System.Text.Encoding.ASCII.GetString(odebraneBajty);
- for(;;)
- try
- {
- if (tmp.Length > 0 || tmp != "quit")
- {
- Console.WriteLine("odebrano komunikat");
- Console.WriteLine(tmp);
- String Cope;
- Cope = Console.ReadLine();
- if (Cope != "w")
- {
- String eko;
- Console.WriteLine("Wyslij komunikat do klienta");
- eko = Console.ReadLine();
- slij(eko);
- Console.WriteLine("Wysłano do klienta");
- Console.ReadKey();
- }
- }
- }
- catch
- {
- Environment.Exit(0);
- }
- tcpLsn.Stop();
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Startuje serwer....");
- serwuj();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement