Why does my laptop not connect to my other laptop?

edited December 2015 in Arduino

So I have this code, and it doesn't want to connect to my server file. It should be able to switch two LED's on and off..

Client:

import processing.net.*;
import processing.serial.*;
Client c;
Serial port;
int incomingbyte;
void setup() {
 c = new Client(this, "127.0.0.1", 12345);
 port = new Serial(this, Serial.list()[0], 9600);
}
void draw() {
 if (c.available()>0) {
     incomingbyte = c.read();
     port.write(incomingbyte);
     println(incomingbyte);
 }
}

Server:

import processing.net.*;
Server s;
void setup() {
 size(400,400);
 rectMode(RADIUS);
 s = new Server(this, 12345);
}
void draw() {
  background(0);
  if (mouseX > 0 && mouseX < 200 && mouseY > 0 && mouseY < 400) {
     fill(0,200,0);
     rect(0,0,200,400);
     s.write('H');
 }
 else{
 s.write("L");
 }
 if (mouseX > 200 && mouseX < 400 && mouseY > 0 && mouseY < 400) {
     fill(200,0,0);
     rect(300,0,100,400);
     s.write('K');
   }
 else {
     s.write('J');
   }
 if (mousePressed){
     s.write('H');
     s.write('K');
   } 
}

Arduino:

const int ledPin = 8; // the pin that the LED is attached to
const int ledPin1 = 7;
int incomingByte;      // a variable to read incoming serial data into
void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin1, OUTPUT);
}
void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    incomingByte = Serial.read();
    if (incomingByte == 'H') {
      digitalWrite(ledPin, HIGH);
    }
    if (incomingByte == 'L') {
      digitalWrite(ledPin, LOW);
    }
    if (incomingByte == 'K') {
      digitalWrite(ledPin1, HIGH);
    }
    if (incomingByte == 'J') {
      digitalWrite(ledPin1, LOW);
    }
  }
}

Answers

  • Answer ✓

    c = new Client(this, "127.0.0.1", 12345);

    127.0.01 is the same machine, try to replace this ip with the one from your server.

Sign In or Register to comment.