๐Ÿ™‡โ€โ™€๏ธConnector

๋ฆฌ์Šค๋„ˆ์™€ ๋ฐ˜๋Œ€๋˜๋Š” ๊ฐœ๋…

๐Ÿช์ฝ”๋“œ

public class Connector
{
    Func<Session> _sessionFactory;

    public void Connect(IPEndPoint endPoint, Func<Session> sessionFactory)
    {
        // ํœด๋Œ€ํฐ ์„ค์ •
        Socket socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
        _sessionFactory = sessionFactory;
        SocketAsyncEventArgs args = new SocketAsyncEventArgs();
        args.Completed += OnConnectCompleted;
        args.RemoteEndPoint = endPoint;
        args.UserToken = socket;

        RegisterConnect(args);
    }

    void RegisterConnect(SocketAsyncEventArgs args)
    {
        Socket socket = args.UserToken as Socket;
        if (socket == null)
            return;

        bool pending = socket.ConnectAsync(args);
        if (pending == false)
            OnConnectCompleted(null, args);
    }

    void OnConnectCompleted(object sender, SocketAsyncEventArgs args)
    {
        if (args.SocketError == SocketError.Success)
        {
            Session session = _sessionFactory.Invoke();
            session.Start(args.ConnectSocket);
            session.OnConnected(args.RemoteEndPoint);
        }
        else
        {
            Console.WriteLine($"OnConnectCompleted Fail : {args.SocketError}");
        }
    }
}

๐Ÿช๋ถ„์„

์ปค๋„ฅํ„ฐ๋ฅผ ๋งŒ๋“œ๋Š” ์ด์œ  : ๋ฆฌ์‹œ๋ธŒ๋ž‘ ์ƒŒ๋“œ๋ฅผ ๊ณต์šฉ์œผ๋กœ ํ•ฉ์น˜๊ธฐ ์œ„ํ•ด, ๋ถ„ํ•  ์„œ๋ฒ„๋ฅผ ํ•  ๋•Œ ํ†ต์‹ ์„ ํ•˜๊ธฐ ์œ„ํ•ด (ํ•œ์ชฝ์€ ๋ฆฌ์Šคํ„ฐ ์ƒํƒœ, ํ•œ์ชฝ์€ ์ปค๋„ฅํŠธ ์ƒํƒœ )

์—ฐ๊ฒฐํ•˜๋Š” ๋ถ€๋ถ„์€ ์ƒ๋Œ€๋ฐฉ์˜ ์ฃผ์†Œ๋ฅผ ๋„ฃ์–ด์ค˜์•ผ ๋จ - args.RemoteEndPoint = endPoint;

Socket์„ ๋งด๋ฒ„๋ณ€์ˆ˜๋กœ ๋‘์ง€ ์•Š๋Š” ์ด์œ  : ์ปค๋„ฅํ„ฐ๋ฅผ ํ•œ๋ช…๋งŒ ๋ฐ›๊ณ  ๋๋‚ด๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ ์—ฌ๋Ÿฌ๋ช…์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฒคํŠธ๋ฅผ ํ†ตํ•ด์„œ ์ธ์ž๋ฅผ ๋„˜๊ฒจ์คŒ

Session.Start(args.ConnectSocket) - Session.Start๋ฅผ ํ•˜๊ธฐ ์œ„ํ•ด ์†Œ์ผ“์ด ํ•„์š”ํ•œ๋ฐ args.ConnectSocket๋กœ ๋„ฃ์–ด์คŒ, Start๋ฅผ ํ–ˆ์œผ๋ฉด Recv์ด๋ฒคํŠธ๋Š” ๋“ฑ๋ก๋œ ์ƒํƒœ

์„œ๋ฒ„์ฝ”์–ด์— ์žˆ๋Š” ์ปค๋„ฅํ„ฐ ๋“ฑ๋“ฑ์˜ ํ•จ์ˆ˜๋ฅผ ํด๋ผ๋ž‘ ์„œ๋ฒ„์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์„œ๋ฒ„์ฝ”์–ด๋ฅผ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋งŒ๋“ค๊ธฐ

๐Ÿช๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

ServerCore ์†์„ฑ -> ์ถœ๋ ฅํ˜•์‹ -> ํด๋ž˜์Šค๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ Server, DummyClient ์ถ”๊ฐ€ -> ์ฐธ์กฐ -> ServerCore์„ ํƒ

ํƒœ๊ทธ:

์นดํ…Œ๊ณ ๋ฆฌ:

์—…๋ฐ์ดํŠธ: