Created
April 20, 2016 00:00
-
-
Save gusthavosouza/33eb89c4272d4e8bdc60bc5566dc6193 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package uscs; | |
import java.io.*; | |
import java.net.*; | |
public class Atv02A { | |
@SuppressWarnings("deprecation") | |
public static void main(String args[]) { | |
String[] codigo = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10" }; | |
String[] descr = { "Produto A", "Produto B", "Produto C", "Produto D", "Produto E", "Produto F", "Produto G", | |
"Produto H", "Produto I", "Produto G" }; | |
try { | |
ServerSocket server2 = new ServerSocket(2222); | |
System.out.println("Servidor ativo na Porta 2222."); | |
Socket clientSocket = server2.accept(); | |
DataInputStream is = new DataInputStream(clientSocket.getInputStream()); | |
PrintStream os = new PrintStream(clientSocket.getOutputStream()); | |
String line = is.readLine(); | |
boolean ativo = true; | |
while (ativo) { | |
String retorna = "Produto nao encontrado"; | |
if (line == null || line.trim().equals("99")) { | |
break; | |
} | |
for (int i = 0; i < 10; i++) { | |
if (line.trim().equals(codigo[i])) { | |
retorna = descr[i]; | |
} | |
} | |
System.out.println("Recebido do cliente:" + line); | |
os.println(retorna); | |
line = is.readLine(); | |
} | |
server2.close(); | |
} catch (IOException e) { | |
System.out.println(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment