who can help me to chek the socket server
bing8206
Junior Member
the socket server can run in the AMX master, or not.
public void run() {
try{
ServerSocket server=null;
try{
server=new ServerSocket(4700);
}catch(Exception e) {
System.out.println("can not listen to:"+e);
}
Socket socket=null;
try{
socket=server.accept();
}catch(Exception e) {
System.out.println("Error."+e);
}
String line;
BufferedReader is=new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter os=new PrintWriter(socket.getOutputStream());
BufferedReader sin=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Client:"+is.readLine());
line=sin.readLine();
while(!line.equals("bye")){
os.println(line);
os.flush();
System.out.println("Server:"+line);
System.out.println("Client:"+is.readLine());
line=sin.readLine();
}
os.close();
is.close();
socket.close();
server.close();
}
catch(Exception e){
System.out.println("Error:"+e);
}
}
Comments
-
While not the most graceful approach, there's nothing that is incompatible with what you have available in Duet. If you place this inside a Duet module verbatim and call run() though you're not going to have a good time. That while loop will only break based on reading "bye" from System.in. I'm not actually sure what the default System.in stream is in Duet, but you'd either need to change that loop or redirect something else to System.in.
As this is all in a run() method too I'll assume that you've copied and pasted from some example code where this is part of a Runnable / Thread object. Whatever implementation you choose, just remember to make sure this server is in a thread otherwise Duet will hit that server.accept() call and block until anything connects (as well as blocking later as you read).
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums