Application Block for socket communication 2.0 Released!

  • Post author:
  • Post category:
  • Post comments:0 Comments
  • Post last modified:August 1, 2020

C++에서 패킷을 struct로 정의해놓고 소켓 통신을 하는 경우가 많은데, C#에서 동일한 방식을 지원하려면 손이 많이 가서 만들었던 라이브러리입니다. 이렇게 바뀌었습니다.

  • MIT 라이센스 채택. (쉽게 말해 상업적 용도로 써도 상관 없습니다.)
  • C# 2.0용으로 변환.
  • 약간의 리팩토링.

  • XML 설정 파일 지원하지 않음.

  • Microsoft Enterprise Library와 같은 외부 라이브러리에 대한 의존성 제거.

라이브러리 소스 코드는 닷넷 프레임워크 기반의 소켓 프로그래밍 가이드에 있습니다. 이 문서를 읽으면 라이브러리가 어떻게 돌아가는지 파악할 수 있습니다.

C# 문자열(System.String)을 ANSI 바이트 코드(char[])로 변환하기
MemoryPacketCommand cmd = new MemoryPacketCommand();

// Create a First Parameter. - Binary
string source1 = "GoodCompany";
byte[] dest1 = StringToByteArray(source1);

MemoryPacketParameter packet1 = new MemoryPacketParameter();
packet1.ParameterName = "@ByteArray1";
packet1.Size = dest1.Length;
packet1.Value = dest1;
packet1.MpType = MpType.Binary;
packet1.FixedSize = false;

// Add a First Parameter to the Command
cmd.Parameters.Add(packet1);

// Create a Memory Packet Byte Array
cmd.ToBytes();
    
ANSI 바이트 코드(char[])를 C# 문자열(System.String)로 변환하기
MemoryPacketCommand cmd = new MemoryPacketCommand();

// Create a First Parameter. - Binary
string sourceString1 = "GoodCompany";
byte[] source1 = StringToByteArray(sourceString1);

MemoryPacketParameter packet1 = new MemoryPacketParameter();
packet1.ParameterName = "@SomeString";
packet1.Size = source1.Length;
packet1.MpType = MpType.String;
packet1.FixedSize = true;

// Add a First Parameter to the Command
cmd.Parameters.Add(packet1);

MemoryPacketParameterCollection collection = cmd.FromBytes(source1);
MemoryPacketParameter newParm1 = (MemoryPacketParameter)collection["@SomeString"];
Assert.AreEqual(sourceString1, newParm1.Value);
    

추후엔 버전 1.5에서 제공했던 XML 설정 파일 기능을 다시 넣으려 합니다. 이번엔 외부 라이브러리에 의존하지 않도록 만들 생각입니다.

Author Details
Kubernetes, DevSecOps, AWS, 클라우드 보안, 클라우드 비용관리, SaaS 의 활용과 내재화 등 소프트웨어 개발 전반에 도움이 필요하다면 도움을 요청하세요. 지인이라면 가볍게 도와드리겠습니다. 전문적인 도움이 필요하다면 저의 현업에 방해가 되지 않는 선에서 협의가능합니다.
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments