-1
package chatserver;
import java.net.*;
import java.io.*;
public class ChatServer implements Runnable
{
static ServerSocket server;
static Socket sc;
private static OutputStream ops;
private static InputStream ips;
private static DataOutputStream dos;
private static DataInputStream dis;
private static String conversation ="";
ChatServer() throws IOException
{
server = new ServerSocket(5000);
System.out.println("Chat Server Started .... ");
new Thread(this).start();
}
public void run()
{
try
{
while(true)
{
sc = server.accept();
ops = sc.getOutputStream();
ips = sc.getInputStream();
dos = new DataOutputStream(ops);
dis = new DataInputStream(ips);
String st = new String(dis.readUTF());
conversation = conversation + "\n"+st;
System.out.println(conversation);
send_to_all();
dos.close();
ops.close();
sc.close();
}
}
catch(IOException ie){}
}
private void send_to_all() throws IException
{
dos.writeUTF(conversation);
}
public static void main(String[] args) throws IOException
{
new ChatServer();
InetAddress sl = server.getInetAddress();
System.out.println("Address : "+sl);
}
}
누군가가 모든 클라이언트에게 다시 모든 메시지를 보내는 메시지를 보내려면 어떻게해야하는지 말해 줄 수 있습니까 !! ?? 좀 더 정확히 말하면, send_to_all() 함수에 무엇을 추가해야합니까 ??? –
질문을 편집하고 현재 내용을 모두 제거한 다음 코드를 다시 붙여넣고 모두 선택하고 '{}'버튼을 사용하여 올바른 구문 강조 표시를하십시오. 또한 질문 자체에 ** 정확하게 ** 귀하의 문제/질문이 무엇인지 (어떤 오류가 발생했는지, 정확하게 작동하지 않는지 등) – Mat
당신은 어떤 오류가 있는지 말할 수 있습니까? – venomrld