C
C0ldC0re
Gast
Hallo Leute,
ich bin grade dabei ein kleines netzwerkfähiges TTT-Spiel zu programmieren!!
Doch nun bin ich an einer Stelle angelangt, an der ich wirklich verzweifel:
Der Borland JBuilder gibt mir dauernd aus, das handleConnection nicht statisch ist und er aus einem statischen Umfeld nicht auf eine nicht-statische Methode zugreifen kann! :### ???:L
Das Problem tritt gleich 2x auf: Zeile 45 und Zeile 67
Hier mein Quellcode:
Könnt ihr mir helfen?
Das wäre supernett!!!! Danke schonmal im vorraus!
C0ldC0re :applaus:
ich bin grade dabei ein kleines netzwerkfähiges TTT-Spiel zu programmieren!!
Doch nun bin ich an einer Stelle angelangt, an der ich wirklich verzweifel:
Der Borland JBuilder gibt mir dauernd aus, das handleConnection nicht statisch ist und er aus einem statischen Umfeld nicht auf eine nicht-statische Methode zugreifen kann! :### ???:L
Das Problem tritt gleich 2x auf: Zeile 45 und Zeile 67
Hier mein Quellcode:
Code:
package tictactoe;
import java.io.*;
import java.net.*;
public class server {
//============================Array========================================
static int[][] array = new int[3][3];
//============================Streams======================================
InputStream in;
OutputStream out;
DataInputStream DataIn = new DataInputStream(in);
DataOutputStream DataOut = new DataOutputStream(out);
int spielerid = 0;
//========================Behandlung einer Verbindung======================
private void handleConnection(Socket client) throws IOException {
in = client.getInputStream();
out = client.getOutputStream();
String inString = DataIn.readUTF();
System.out.println("Ankommender String: " + inString);
if (inString.contains("SrvArraySet")) {
int pos1 = Integer.parseInt(inString.substring(12, 13));
int pos2 = Integer.parseInt(inString.substring(14, 15));
int wert = Integer.parseInt(inString.substring(16));
SrvArraySet(pos1, pos2, wert);
}
//int factor1 = in.read();
//int factor2 = in.read();
//out.write(factor1 * factor2);
}
public static void main(String[] args) throws IOException {
//============================ServerSockets================================
final ServerSocket serversoc1 = new ServerSocket(3141);
final ServerSocket serversoc2 = new ServerSocket(3142);
//=======================Thread1===========================================
class SrvThread1 implements Runnable {
public void run() {
while (true) {
Socket client = null;
try {
client = serversoc1.accept();
handleConnection(client);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (client != null)
try {
client.close();
} catch (IOException e) {}
}
}
}
}
//=======================Thread2===========================================
class SrvThread2 implements Runnable {
public void run() {
while (true) {
Socket client = null;
try {
client = serversoc2.accept();
handleConnection(client);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (client != null)
try {
client.close();
} catch (IOException e) {}
}
}
}
}
}
//======================SrvArraySet========================================
public void SrvArraySet(int aPos1, int aPos2, int wert) throws IOException {
System.out.println("Array Ausgabe: [" + aPos1 + "][" + aPos2 + "]= " +
array[aPos1][aPos2]);
if (wert < 30) {
spielerid = 1;
} else {
spielerid = 2;
}
if (array[aPos1][aPos2] == 0) {
array[aPos1][aPos2] = wert;
DataOut.writeUTF("Feld wurde für Spieler " + spielerid +
" markiert!");
} else {
if (array[aPos1][aPos2] == 1) {
DataOut.writeUTF(
"Fehler: Feld ist schon von Spieler 1 markiert!");
} else {
if (array[aPos1][aPos2] == 30) {
DataOut.writeUTF(
"Fehler: Feld ist schon von Spieler 2 markiert!");
}
}
}
}
//======================SrvArrayRequest====================================
/* public void SrvArrayRequest() {
}
*/
}
Könnt ihr mir helfen?
Das wäre supernett!!!! Danke schonmal im vorraus!
C0ldC0re :applaus: