Recently, my tutor asked me to develop a mobile phone class sign-In application with another student. I am responsible for the communication architecture between the client and the server and data storage.
I have only used compilation and C/C ++ for four years in college, so I still have no idea about andriod development. I spent a week writing basic communication functions.
The first is the server architecture:
There are three main types of network communication threads in network communication. One is that the scheduled multicast thread broadcasts the ip address of the host machine in the same LAN to all student machines. Because one AP supports a small number of connections, this is why regular multicast is used. The second is to listen to the thread, accept the tcp connection of the student machine, and then generate a new sign-In Transaction Thread. The third is the Transaction Thread, which processes the student's sign-in information and returns the sign-in status. The database uses Sqlite, which comes with andriod. Because there are a large number of transaction threads, it is necessary to do a good job of thread synchronization.
wifiManager= mButton.setOnClickListener( mEcho = mEcho.setText("begin" TCPListenThread tcpListenThread = MulticastThread multicastThread = multicastThread.start();
Log.i(TAG, "In MulticastThread.run()" InetAddress address = multicastSocket = ( i = 0; i != 100; ++ String msg = "I'm the teacher, my IP Address is?" + [] buf = DatagramPacket packet= Thread.sleep(1000 } } } .run();
Log.i(TAG, "In TCPListenThread.run()" listenSocket = ( CheckinSocket = CheckinThread checkinThread = } }
Log.i(TAG, "In CheckinThread.run()" InputStreamReader input = InputStreamReader( checkinSocket.getInputStream(),"UTF-8" [] b = [1024 StringBuilder builder = (( i = input.read(b)) != -1 String msg = Log.i(TAG, "In CheckinThread.run() msg:"+ } }
After testing with multiple hosts, the server can work normally. However, since I only have one week of development experience in Android, the code in the server will inevitably have deficiencies and bugs. I hope you can point it out. Thank you ~~