Aplikacja serwera (konsola)

0

Witam.
Potrzebuję pomocy z poniższym kodem:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Threading;

namespace server_App
{
    class Program
    {
        
        

        static void Main(string[] args)
        {
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Unspecified);
            s.Bind(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 3301));
            s.Listen(5);

            int counter = 0;
            
            

            while (true)
            {
                Console.WriteLine("Waiting for connection...");
                Thread new_client = new Thread(new ThreadStart(startClient));
                new_client.Start();
                 
            }

            
            
        }

        public static void startClient()
        {
            Socket cli = s.Accept();
            Console.WriteLine("Połączono");

            try
            {
                byte[] buffer = new byte[1024];
                int wynik = cli.Receive(buffer);
                String time = Encoding.ASCII.GetString(buffer, 0, wynik);
                Console.WriteLine("Client >> " + time);

                if (wynik != 0)
                {
                    String respond = "Roger";
                    byte[] responddata = Encoding.ASCII.GetBytes(respond.ToString());
                    cli.Send(responddata);


                }
            }
            catch { }
        }
    }
}
 

Wywala:
Error 2 The name 's' does not exist in the current context w metodzie startClient nie widzi socketa s:( Wiem, że to jakiś prosty błąd pewnie ale dopiero się uczę:p

0

Popatrz gdzie tworzysz "s" i jaki ma zakres.

1 użytkowników online, w tym zalogowanych: 0, gości: 1