Git Product home page Git Product logo

.net-android-socket-with-json's Introduction

Android<->C# JSON을 통한 소켓 통신 구현

사실 이런 특이 케이스는 별로 없을듯 하지만...

회사에서 Android 클라이언트가 닷넷(.net)서버 어플리케이션에서 정보를 가져오는 작업을 구현해야할 일이 생겼는데,

닷넷 버전으로 인해서 REST API를 구축하는 라이브러리를 사용을 못하는 상황을 마주하게 되었다.

기존에 구현되어 있던 방식을 이용하려고 했으나, 

어느순간 좋지 않은 방법이라는 것을 깨닫고

직접 json으로 소통할 수 있게 소켓서버를 구현하기로 맘먹었다.

GitHub 프로젝트 주소 : https://github.com/kyunooh/.net-android-socket-with-json

거의 없는 정보들...

C#서버와 안드로이드 클라이언트를 기준으로 하는 예제들은 사실 거의 없고,

있어도 제대로 정리 된 예제들이 없어서 깃허브 프로젝트로 공유하게 되었습니다.

유의해서 보면 되는 곳

C#(.NET) Server

C#쪽은 Listener Thread를 띄어서 요청이 오면 그냥 json데이터를 던져주도록 하였습니다.

실무에서 사용하게 될경우 리플렉션과 같이 적절한 분기를 통해서 응답을 주도록 변경해주면 됩니다.

(본 프로젝트는 .net 3.5 버전에서 테스트 하였습니다.)

Android Client

안드로이드의 경우 까다로운데

안드로이드에서 MainThread(UIThread)가 네트워크 통신을 하는게 막혀져 있습니다.

그래서 새로 쓰레드를 띄어서 데이터를 받아오고 또 새로 띄운 쓰레드가 다시 UIThread에 접근하지 못하기 때문에

안드로이드 메시지 핸들러를 이용해서 비동기처럼 처리해야합니다.

이부분만 유의해주시면 안드로이드 개발자이신 분들이 저보다 더 잘 아실것이라 생각됩니다.

 

.net-android-socket-with-json's People

Contributors

dev-jelly avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.