Source code
Http://www.eoeandroid.com/thread-114907-1-1.html
Self-implemented Android curve chart
Http://www.eoeandroid.com/thread-207218-1-1.html
Android game physical engine source code
Http://www.eoeandroid.com/thread-207445-1-1.html
Socketserver class
Package Com. Socket. server; Import Java. Io .* ; Import Java.net .* ; Import Android. content. context; Import Android. content. intent; Public Class Socketserver {serversocket sever; Context context; Public Socketserver (context, Int Port ){ Try { // Instantiate the serversocket input port number Sever = New Serversocket (port ); This . Context = Context ;} Catch (Ioexception e) {e. printstacktrace ();}} Public Void Controlactionanswermsg (string Str ){ Final Intent intent = New Intent (); intent. setaction ( "Socket_action" ); Intent. putextra ( "Message" , STR); context. sendbroadcast (intent );} Public Void Beginlisten (){ // Put the socket listener into the thread to prevent the main thread from being affected. New Thread (){ Public Void Run (){ // Because it is a process of continuous listening, it uses an endless loop. While ( True ){ Try { // Here is the listener operation Final Socket socket = Sever. Accept (); bufferedreader in; Try { // Read the stream information here after listening to the message In = New Bufferedreader ( New Inputstreamreader (socket. getinputstream (), UTF-8" )); // Put the stream information in printwriter and read it out. Printwriter out = New Printwriter (socket. getoutputstream ()); While (! Socket. isclosed () {string STR; // Read string STR = In. Readline (); Out. println ( "Hello! World !! "+ Str); Out. Flush (); If (STR = Null | Str. Equals ("end" )) Break ; System. Out. println (STR); controlactionanswermsg (STR);} socket. Close ();} Catch (Ioexception e) {e. printstacktrace ();}} Catch (Ioexception e) {e. printstacktrace () ;}}}. start ();}}
Clientsocket class
Package Com. Socket. PC; Import Java. Io .* ; Import Java.net .* ; Public Class Clientsocket { Static Socket Client; Public Clientsocket (string site, Int Port ){ Try { // Input the IP address and port number to instantiate the socket. The port numbers on both sides must be consistent. Client = New Socket (site, Port); system. Out. println ( "Client is created! Site: "+ site +" port: "+ Port );} Catch (Unknownhostexception e) {e. printstacktrace ();} Catch (Ioexception e) {e. printstacktrace ();}} Public String sendmsg (string MSG ){ Try { // Bufferedreader in = new bufferedreader (New inputstreamreader ( // Client. getinputstream ())); // Convert the string to the output stream and send it out. Printwriter out = New Printwriter (client. getoutputstream (); Out. println (MSG); Out. Flush (); // Return in. Readline (); } Catch (Ioexception e) {e. printstacktrace ();} Return "" ;} Public Void Closesocket (){ Try {Client. Close ();} Catch (Ioexception e) {e. printstacktrace ();}}}
Server and client source code