java socket 编写的聊天程序可发我吗,谢谢
2个回答
展开全部
package
myfistsocket;
/*
一个作为
Server*/
import
java.io.*;
import
java.net.*;
class
MynewServer
{
public
static
void
main(String[] args)
throws
IOException
{
ServerSocket s =
new
ServerSocket(6666);
System.out.println("
服务器端
------
监听中
.....");
Socket socket = s.accept();
System.out.println("
开始:
" + socket);
GetMessage gm =
new
GetMessage(socket);
SendMessage sm =
new
SendMessage(socket);
Thread gt =
new
Thread(gm);
Thread st =
new
Thread(sm);
gt.start();
st.start();
}
}
//
接收消息
class
GetMessage
implements
Runnable
{
BufferedReader in;
public
GetMessage(Socket socket)
{
try
{
in =
new
BufferedReader(
new
InputStreamReader(socket.getInputStream()));
}
catch
(IOException e)
{
e.printStackTrace();
java socket 聊天程序http://wenku.baidu.com/view/bc59693f580216fc700afddb.html
myfistsocket;
/*
一个作为
Server*/
import
java.io.*;
import
java.net.*;
class
MynewServer
{
public
static
void
main(String[] args)
throws
IOException
{
ServerSocket s =
new
ServerSocket(6666);
System.out.println("
服务器端
------
监听中
.....");
Socket socket = s.accept();
System.out.println("
开始:
" + socket);
GetMessage gm =
new
GetMessage(socket);
SendMessage sm =
new
SendMessage(socket);
Thread gt =
new
Thread(gm);
Thread st =
new
Thread(sm);
gt.start();
st.start();
}
}
//
接收消息
class
GetMessage
implements
Runnable
{
BufferedReader in;
public
GetMessage(Socket socket)
{
try
{
in =
new
BufferedReader(
new
InputStreamReader(socket.getInputStream()));
}
catch
(IOException e)
{
e.printStackTrace();
java socket 聊天程序http://wenku.baidu.com/view/bc59693f580216fc700afddb.html
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询