私のプログラムは設定され準備ができています。問題はサーバー内にあります。クライアントがメッセージを送信すると、どこに保存する必要がありますか? キューを使用してみましたが機能しませんでした。また、通常の文字列レジスタを使用しようとしましたが、部分的に機能しました。「読み取り/書き込みUTF」を使用して、送信用のスレッドと保存用のスレッドを作成しました。誰かがアルゴリズム、または少なくともより良いアイデアを提供してくれたら、私はとても感謝しています。コード :
class clientThread extends Thread {
DataInputStream fromClient;
int counter = 0;
public clientThread(Socket cs) throws IOException
{
fromClient = new DataInputStream(cs.getInputStream());
}
public void run()
{
while (true)
{
try {
toall=Integer.toString(counter)+fromClient.readUTF();
} catch (IOException ex) {
Logger.getLogger(ChatTerminalS.class.getName()).log(Level.SEVERE, null, ex);
}
counter++;
}
}
}
class SendingThread extends Thread
{
DataOutputStream toClient;
String s = "";int counter=0;
public SendingThread(Socket cs) throws IOException
{
toClient = new DataOutputStream(cs.getOutputStream());
}
public void run()
{
while (true)
{
if(toall.charAt(0)+""==Integer.toString(counter))
{}
else
{
try {
toClient.writeUTF(toall);
} catch (IOException ex) {
Logger.getLogger(ChatTerminalS.class.getName()).log(Level.SEVERE, null, ex);
}
counter++;
}
}
}