HTTP data rerouting
in
Core Library Questions
•
1 years ago
hello, for access rights validation for my IPcam (that hasn't this option), I wish to reroute datas between web Client and the IPcam through an applet Server.
This:
Client HTTPdata > Server in plugin reads HTTPdata > plugin forward HTTPdata to IPcam
IPcam answers to Server in plugin > Server reads all the data > Server forward all the data to Client
Code is working in one way. I did succeed to forward datas to the IPcam, but I dont get any answer.
I the hope idea is comprehensible. I'll appreciate if you look into my easy code. and write some hints.
- import processing.net.*;
- int portServer = 8081;
- int portIPcam = 8082;
- boolean myServerRunning = true;
- Server myServer;
- Client myIPcam;
- void setup()
- {
- size(400, 400);
- myServer = new Server(this, portServer); // Starts a myServer on port
- myIPcam = new Client(this, "198.168.1.3", portIPcam); // Starts a myIPcam to comunicate with IP cam
- background(0);
- }
- void mousePressed()
- {
- // If the mouse clicked the myServer stops
- myServer.stop();
- myServerRunning = false;
- }
- void draw()
- {
- if (myServerRunning == true)
- {
- Client thisClient = myServer.available();
- if (thisClient != null) {
- if (thisClient.available() > 0) {
- byte[] byteBuffer = new byte[100];
- int byteCount = thisClient.readBytes(byteBuffer);
- if (byteCount > 0 ) {
- myIPcam.write(byteBuffer);
- // Convert the byte array to a String
- String myString = new String(byteBuffer);
- // Show it text area
- print(myString);
- }
- }
- if (myIPcam.available() > 0) {
- int inData = myIPcam.read();
- if (inData > 0 ) {
- thisClient.write(inData);
- // Show it text area
- print(inData);
- }
- }
- }
- }
- else
- {
- background(0);
- text("no client", 15, 25);
- text("server", 15, 45);
- text("stopped", 15, 65);
- }
- }
1