0 Membros e 1 Visitante estão a ver este tópico.
<META HTTP-EQUIV=Refresh CONTENT="5">
import java.lang.*;import java.io.*;import java.net.*;class Client { public static void main(String args[]) { try { Socket skt = new Socket("localhost", 1234); BufferedReader in = new BufferedReader(new InputStreamReader(skt.getInputStream())); System.out.print("Received string: '"); while (!in.ready()) {} System.out.println(in.readLine()); // Read one line and output it System.out.print("'\n"); in.close(); } catch(Exception e) { System.out.print("Whoops! It didn't work!\n"); } }}
/* * Chat Server * * A simple server that distributes any incoming messages to all * connected clients. To use telnet to 10.0.0.177 and type! */#include <Ethernet.h>#include <WString.h>// network configuration. gateway and subnet are optional.byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };byte ip[] = { xxx,xxx,xxx,xxx };byte gateway[] = { xxx,xxx,xxx,xxx };byte subnet[] = { xxx,xxx,xxx,xxx };// telnet defaults to port 23Server server(1234);// the number of the pushbutton pinconst int button = 2; // the number of the LED pinsconst int red = 8;const int yellow = 6;const int green = 4;// variable for reading the pushbutton statusint buttonState = LOW; // initialize varibles String readString = String(30); //string for fetching data from addressString bell = String(30);void setup(){ // initialize the ethernet device Ethernet.begin(mac, ip, gateway, subnet); delay(1000); // start listening for clients server.begin(); //pc.connect(); //Set pin 2,4 and 6 to output pinMode(green, OUTPUT); //Green LED pinMode(yellow, OUTPUT); //Yellow LED pinMode(red, OUTPUT); //Red LED pinMode(button,INPUT); //Push button}void loop(){ buttonState=digitalRead(button); if(server.available()){ switchLed(); } if(buttonState==HIGH){ server.begin(); String b="bell"; server.println(b); //digitalWrite(green,HIGH); delay(1000); buttonState=LOW; }}void switchLed(){ Client pc = server.available(); readString=""; char input = pc.read(); pc.println(input); readString.append(input); if(readString.contains("g")){ digitalWrite(green,HIGH); digitalWrite(red,LOW); digitalWrite(yellow,LOW); readString=""; } if(readString.contains("y")){ digitalWrite(green,LOW); digitalWrite(red,LOW); digitalWrite(yellow,HIGH); readString=""; } if(readString.contains("r")){ digitalWrite(green,LOW); digitalWrite(red,HIGH); digitalWrite(yellow,LOW); readString=""; }}
Está com bom aspecto Tu não consegues colocar esse programa em java dentro de uma página web? Tipo como as vezes quando abrimos uma página em que aparece o logo grande do java a carregar.
Não sei bem como é que isto se chama mas o seguinte código:Código: [Seleccione]<META HTTP-EQUIV=Refresh CONTENT="5">faz com que a página seja recarregada de x em x segundos, nesse caso ao carregares num botão isso ia alterar o código da pagina podendo da próxima vez que a página é recarregada aparecer o aviso. Espero ter-me feito entender.