728x90
반응형
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace Network_Async_Test
{
class Program
{
static void Main(string[] args)
{
Socket aSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
aSocket.Bind(new IPEndPoint(0, 5000));
aSocket.Listen(5);
aSocket.BeginAccept(new AsyncCallback(Jue_Listen), aSocket);
while (true)
{
Console.Write(".");
Thread.Sleep(500);
}
}
static void Jue_Listen(IAsyncResult aIAsyncResult)
{
Console.WriteLine("게스트 접속");
Socket aSocket = (Socket)(aIAsyncResult.AsyncState);
Socket aClient = aSocket.EndAccept(aIAsyncResult);
byte[] Tempdata = Encoding.UTF8.GetBytes("Apple\n\r");
aClient.Send(Tempdata, Tempdata.Length, SocketFlags.None);
aClient.Receive(Tempdata, Tempdata.Length, SocketFlags.None);
aClient.Close();
aSocket.BeginAccept(new AsyncCallback(Jue_Listen), aSocket);
}
}
}
Tested By VS2019
728x90
'기술자료 > C#' 카테고리의 다른 글
C# Console 비동기 입력 ReadLine ReadKey Asynchronous input 초간단 소스 (0) | 2021.09.15 |
---|---|
C# Packet Capture Programming #4 - 패킷 출력 HexaView (0) | 2021.09.07 |
C# Packet Capture Programming #3 - 패킷 캡쳐 GetNextPacket (0) | 2021.09.07 |
static HexaViewer Class 구현 - ArraySegment 응용 (0) | 2021.09.07 |
C# Packet Capture Programming #2 - 캡쳐 장치 선정 ICaptureDevice (0) | 2021.09.01 |
C# Packet Capture Programming #1 (0) | 2021.09.01 |
예외처리 1 : try catch 문법 (0) | 2021.06.10 |
포인터 사용 C# Pointer unsafe (0) | 2021.04.29 |