-1

I am practicing networking in java, and I intend to send a file via SocketChannel, with the host and port specified by the user. However when I declare the variables Eclipse gives the error message:

"Syntax error on tokes, delete these tokens" EDIT: (This error message pops up next to the declarations of port and host)

This is my code:

public int port;
public String host;

public class Client {

public static void main (String[] args) {

    System.out.print("Enter host/ip: ");
    Scanner inputHost = new Scanner(System.in);
    host = inputHost.next();

    System.out.print("Enter port: ");
    Scanner inputPort = new Scanner(System.in);
    port = inputPort.nextInt();




    Client client = new Client();
    SocketChannel channel = client.createChannel();
    client.sendFile(channel);
joyalrj22
  • 115
  • 4
  • 12

1 Answers1

0

The port and host variables need to be defined in the class variable and based on their usage in static method main they need to be declared static.

LhasaDad
  • 1,786
  • 1
  • 12
  • 19