mirror of
https://github.com/brendanhaines/RasPi.git
synced 2024-11-09 16:44:40 -07:00
minor updates
This commit is contained in:
parent
a0fd3efb89
commit
98526900c7
51
CopterController/TCPexample/EchoServer.java
Normal file
51
CopterController/TCPexample/EchoServer.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
import java.lang.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
/**
|
||||
* Echo server. if receives "DISCONNECT", will shut down server properly
|
||||
*/
|
||||
class EchoServer {
|
||||
public static void main(String args[]) {
|
||||
ServerSocket srvr;
|
||||
Socket skt;
|
||||
BufferedReader in;
|
||||
PrintWriter out;
|
||||
|
||||
try {
|
||||
System.out.print( "Setting up server\n" );
|
||||
srvr = new ServerSocket( 51717 );
|
||||
skt = srvr.accept();
|
||||
System.out.print( "Server has connected!\n" );
|
||||
|
||||
in = new BufferedReader( new InputStreamReader( skt.getInputStream() ) );
|
||||
out = new PrintWriter( skt.getOutputStream(), true);
|
||||
|
||||
while( true ) {
|
||||
System.out.print( "waiting for message...\n" );
|
||||
while( !in.ready() ) {}
|
||||
String rx = in.readLine();
|
||||
System.out.print( "message received: " + rx + "\n" );
|
||||
|
||||
if( rx.equals( "DISCONNECT" ) ) {
|
||||
System.out.print( "disconnecting\n" );
|
||||
break;
|
||||
}
|
||||
|
||||
System.out.print("Sending string: '" + rx + "'\n");
|
||||
out.println( rx );
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
skt.close();
|
||||
srvr.close();
|
||||
}
|
||||
catch(Exception e) {
|
||||
System.out.print("Whoops! It didn't work!\n");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ import java.net.*;
|
|||
|
||||
/**
|
||||
* Echo server. if receives "DISCONNECT", will shut down server properly
|
||||
* Used for testing GroundStation communications
|
||||
*/
|
||||
class Server {
|
||||
public static void main(String args[]) {
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user