سؤال

In my application I need to connect several (clients) devices to one (server) device. I need it to work in a LAN, so no remote server. The requirements are:

Must have:

  • ability for the clients to find the server with a discovery (no manual ip input)
  • ability for the server to know which client is connected
  • ability to send big set of data (pictures, etc) from server to clients
  • ability to send commands (in form of strings or json) from server to client and viceversa

Should have:

  • ability to send big set of data (pictures, etc) from clients to server
  • ability to encrypt all data and commands with a short password

My googlefu is not helping me in this search, I'm lacking good search terms. What I'm asking is not some code, I'm asking for some advice on which technology to use and if it is doable at all in Android. Some good articles or tutorials are very welcome.

هل كانت مفيدة؟

المحلول

I would suggest using a client-server socket implementation. You can perform an IP broadcast and have your server respond to specific clients. Once the initial response is made, you can transfer data whichever way you like.

It basically boils down to:

  • Client creates a socket connecting to the broadcast IP on a preset port, and listens for incoming connections
  • Server listens on that port and responds to any incoming connections
  • Client receives a response from the server and replies with details about its client identity
  • Any other data is transmitted through the now established socket connection

Bear in mind that by using a socket, you're riding on a bare IP datagram and simply providing its body in raw binary data. This means that you'll have to manually write your protocol in order to cope with request and response types, dropped packets and any other limitations of IP. You may want to look around for a TCP implementation layer or something more sophisticated for your purpose.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top