如何在java服务器中发送点(x,y)?

如何在java服务器中发送点(x,y)?,java,Java,我正在尝试将一个Skor4游戏(或两个玩家)改为tic tac toe。问题是,在我试图更改的源代码中,只将球的x维度发送给服务器,然后另一个玩家获取该x维度并找到y维度。在我的情况下,我想发送x和y维度。我该怎么做 玩家玩游戏时: else if (myMove) { Point pos = gameEngine.makeMove(0, x/160, y/162);// if (pos.y >= 0) { if (!gameEngine.isWinner(0))

我正在尝试将一个Skor4游戏(或两个玩家)改为tic tac toe。问题是,在我试图更改的源代码中,只将球的x维度发送给服务器,然后另一个玩家获取该x维度并找到y维度。在我的情况下,我想发送x和y维度。我该怎么做

玩家玩游戏时:

else if (myMove) {
  Point pos = gameEngine.makeMove(0, x/160, y/162);//
  if (pos.y >= 0) {
    if (!gameEngine.isWinner(0))
      if (!gameEngine.isTie()) {
        redSnd.play();
        status = new String("Their turn.");
        connection.sendMove(pos.x);  //
        myMove = false;
public void sendMove(int col) {
  String s = (new Integer(col)).toString();
  send(s);
}
public void send(String s) {
  outStream.println(s);
}
int istatus = connection.getTheirMove();
public int getTheirMove() {
  // Make sure we're still connected
  if (!isConnected()) 
    throw new NullPointerException("Attempted to read closed socket!");
  try {
    String s = receive();
    System.out.println("Received: " + s);
    if (s == null)
      return GAMEOVER;
    s = s.trim();

    try {
      return (new Integer(s)).intValue();
    } catch (NumberFormatException e) {
        // It was probably a status report error
        return getStatus(s);
    }
  } catch (IOException e) {
      System.out.println("I/O Error: " + e);
      System.exit(1);
      return 0;
    }
  }
public String receive() throws IOException {
    return inStream.readLine();
}
这是发送移动:

else if (myMove) {
  Point pos = gameEngine.makeMove(0, x/160, y/162);//
  if (pos.y >= 0) {
    if (!gameEngine.isWinner(0))
      if (!gameEngine.isTie()) {
        redSnd.play();
        status = new String("Their turn.");
        connection.sendMove(pos.x);  //
        myMove = false;
public void sendMove(int col) {
  String s = (new Integer(col)).toString();
  send(s);
}
public void send(String s) {
  outStream.println(s);
}
int istatus = connection.getTheirMove();
public int getTheirMove() {
  // Make sure we're still connected
  if (!isConnected()) 
    throw new NullPointerException("Attempted to read closed socket!");
  try {
    String s = receive();
    System.out.println("Received: " + s);
    if (s == null)
      return GAMEOVER;
    s = s.trim();

    try {
      return (new Integer(s)).intValue();
    } catch (NumberFormatException e) {
        // It was probably a status report error
        return getStatus(s);
    }
  } catch (IOException e) {
      System.out.println("I/O Error: " + e);
      System.exit(1);
      return 0;
    }
  }
public String receive() throws IOException {
    return inStream.readLine();
}
这里是send:

else if (myMove) {
  Point pos = gameEngine.makeMove(0, x/160, y/162);//
  if (pos.y >= 0) {
    if (!gameEngine.isWinner(0))
      if (!gameEngine.isTie()) {
        redSnd.play();
        status = new String("Their turn.");
        connection.sendMove(pos.x);  //
        myMove = false;
public void sendMove(int col) {
  String s = (new Integer(col)).toString();
  send(s);
}
public void send(String s) {
  outStream.println(s);
}
int istatus = connection.getTheirMove();
public int getTheirMove() {
  // Make sure we're still connected
  if (!isConnected()) 
    throw new NullPointerException("Attempted to read closed socket!");
  try {
    String s = receive();
    System.out.println("Received: " + s);
    if (s == null)
      return GAMEOVER;
    s = s.trim();

    try {
      return (new Integer(s)).intValue();
    } catch (NumberFormatException e) {
        // It was probably a status report error
        return getStatus(s);
    }
  } catch (IOException e) {
      System.out.println("I/O Error: " + e);
      System.exit(1);
      return 0;
    }
  }
public String receive() throws IOException {
    return inStream.readLine();
}
之后,其他玩家收到移动:

else if (myMove) {
  Point pos = gameEngine.makeMove(0, x/160, y/162);//
  if (pos.y >= 0) {
    if (!gameEngine.isWinner(0))
      if (!gameEngine.isTie()) {
        redSnd.play();
        status = new String("Their turn.");
        connection.sendMove(pos.x);  //
        myMove = false;
public void sendMove(int col) {
  String s = (new Integer(col)).toString();
  send(s);
}
public void send(String s) {
  outStream.println(s);
}
int istatus = connection.getTheirMove();
public int getTheirMove() {
  // Make sure we're still connected
  if (!isConnected()) 
    throw new NullPointerException("Attempted to read closed socket!");
  try {
    String s = receive();
    System.out.println("Received: " + s);
    if (s == null)
      return GAMEOVER;
    s = s.trim();

    try {
      return (new Integer(s)).intValue();
    } catch (NumberFormatException e) {
        // It was probably a status report error
        return getStatus(s);
    }
  } catch (IOException e) {
      System.out.println("I/O Error: " + e);
      System.exit(1);
      return 0;
    }
  }
public String receive() throws IOException {
    return inStream.readLine();
}
这是他们的行动:

else if (myMove) {
  Point pos = gameEngine.makeMove(0, x/160, y/162);//
  if (pos.y >= 0) {
    if (!gameEngine.isWinner(0))
      if (!gameEngine.isTie()) {
        redSnd.play();
        status = new String("Their turn.");
        connection.sendMove(pos.x);  //
        myMove = false;
public void sendMove(int col) {
  String s = (new Integer(col)).toString();
  send(s);
}
public void send(String s) {
  outStream.println(s);
}
int istatus = connection.getTheirMove();
public int getTheirMove() {
  // Make sure we're still connected
  if (!isConnected()) 
    throw new NullPointerException("Attempted to read closed socket!");
  try {
    String s = receive();
    System.out.println("Received: " + s);
    if (s == null)
      return GAMEOVER;
    s = s.trim();

    try {
      return (new Integer(s)).intValue();
    } catch (NumberFormatException e) {
        // It was probably a status report error
        return getStatus(s);
    }
  } catch (IOException e) {
      System.out.println("I/O Error: " + e);
      System.exit(1);
      return 0;
    }
  }
public String receive() throws IOException {
    return inStream.readLine();
}
这里是接收:

else if (myMove) {
  Point pos = gameEngine.makeMove(0, x/160, y/162);//
  if (pos.y >= 0) {
    if (!gameEngine.isWinner(0))
      if (!gameEngine.isTie()) {
        redSnd.play();
        status = new String("Their turn.");
        connection.sendMove(pos.x);  //
        myMove = false;
public void sendMove(int col) {
  String s = (new Integer(col)).toString();
  send(s);
}
public void send(String s) {
  outStream.println(s);
}
int istatus = connection.getTheirMove();
public int getTheirMove() {
  // Make sure we're still connected
  if (!isConnected()) 
    throw new NullPointerException("Attempted to read closed socket!");
  try {
    String s = receive();
    System.out.println("Received: " + s);
    if (s == null)
      return GAMEOVER;
    s = s.trim();

    try {
      return (new Integer(s)).intValue();
    } catch (NumberFormatException e) {
        // It was probably a status report error
        return getStatus(s);
    }
  } catch (IOException e) {
      System.out.println("I/O Error: " + e);
      System.exit(1);
      return 0;
    }
  }
public String receive() throws IOException {
    return inStream.readLine();
}
那为什么不发送呢

  String coord =  x + "," + y; 
然后用?这将为您提供一个由两个字符串组成的数组-x和y

更进一步说,您可能希望发送(说)一些东西来确定您的消息是什么,然后是数据。然后使用类似的方法明确地分割数据。e、 g.消息可能看起来像:

COORD:x,y
STATUS: message

等等。

谢谢……我利用你的帮助解决了我的问题……非常感谢