帮我写一个简单的聊天室啊 socket
帮我写一个简单的聊天室啊 socket
[解决办法]
[解决办法]
给一个服务器端的简单代码:
import java.io.DataInputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class ChatServer
{
public static void main(String[] args)
{
boolean started=false;
DataInputStream dis=null;
try
{
ServerSocket s=new ServerSocket(8888);
started=true;
while(started)
{
boolean beConnected=false;
Socket ss=s.accept();
beConnected=true;
System.out.println("你已经登陆了");
dis=new DataInputStream(ss.getInputStream());
while(beConnected)
{
try
{
String str=dis.readUTF();
System.out.println(str);
}
catch(IOException e)
{
System.out.println("你已经退出了服务器");
dis.close();
ss.close();
beConnected=false;
}
}
}
}
catch (IOException e)
{
System.out.println("启动服务器失败,请重启");
}
}
}
[解决办法]
顶!!!!!!!!!