witam, do zrobienia mam gierkę kalambury która ma się składać z serwera i klienta. Udało mi się zrobić tylko czat, ale nie wiem jak dołączyć do tego rysowanie, to wszystko ma być w JPanelu. Proszę o pomoc
serwer
[code]
import java.io.;
import java.net.;
public class server {
static Socket klientSocket = null;
static ServerSocket serwerSocket = null;
static klientwatek klienci[] = new klientwatek[4];
public static void main(String args[]) {
int numerPortu = 2500;
try {
serwerSocket = new ServerSocket(numerPortu);
}
catch (IOException e) {
System.out.println(e);
}
while (true) {
try {
klientSocket = serwerSocket.accept();
for (int idx = 0; idx <= 3; idx++) {
if (klienci[idx] == null) {
(klienci[idx] = new klientwatek(klientSocket, klienci)).start();
break;
}
}
} catch (IOException e) {
System.out.println(e);
}
}
}
}
[/code]
klient
[code]
import java.io.;
import java.net.;
public class klient implements Runnable {
static Socket klientSocket = null;
static PrintStream outputStream = null;
static DataInputStream inputStream = null;
static BufferedReader inputLine = null;
static boolean zamkniety = false;
public static void main(String[] args) {
int numerPortu = 2500;
String host = "localhost";
try {
klientSocket = new Socket(host, numerPortu);
inputLine = new BufferedReader(new InputStreamReader(System.in));
outputStream = new PrintStream(klientSocket.getOutputStream());
inputStream = new DataInputStream(klientSocket.getInputStream());
}
catch (UnknownHostException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
if (klientSocket != null && outputStream != null && inputStream != null) {
try {
new Thread(new klient()).start();
while (!zamkniety) {
outputStream.println(inputLine.readLine());
}
outputStream.close();
inputStream.close();
klientSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void run() {
String odpowiedzi;
try {
while ((odpowiedzi = inputStream.readLine()) != null) {
System.out.println(odpowiedzi);
}
zamkniety = true;
}
catch (IOException e) {
e.printStackTrace();
}
}
}
[/code]
klient watek
[code]
import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.Socket;
class klientwatek extends Thread {
DataInputStream inputStream = null;
PrintStream outputStream = null;
Socket klientSocket = null;
klientwatek klienci[];
public klientwatek(Socket klientSocket, klientwatek[] klienci) {
this.klientSocket = klientSocket;
this.klienci = klienci;
}
public void run() {
String linia;
String nick;
try {
inputStream = new DataInputStream(klientSocket.getInputStream());
outputStream = new PrintStream(klientSocket.getOutputStream());
outputStream.println("Podaj nick");
nick = inputStream.readLine();
while (true) {
linia = inputStream.readLine();
if (linia.startsWith("/out")) {
break;
}
for (int idx = 0; idx <= 3; idx++) {
if (klienci[idx] != null) {
klienci[idx].outputStream.println("<" + nick + "> " + linia);
}
}
}
for (int idx = 0; idx <= 3; idx++) {
if (klienci[idx] == this) {
klienci[idx] = null;
}
}
inputStream.close();
outputStream.close();
klientSocket.close();
} catch (IOException e) {
};
}
}
[/code]