客户端 不能发送信息到服务器端?(在SOCKET)请看看下面这段程序有什么错?----客户端的发送信息服务器端收不了!

rwq_ 2001-07-22 12:30:27
//服务器端 !
import java.net.*;
import java.io.*;
public class SimpleServer
{
public static void main(String args[])
{
ServerSocket s=null;
Socket s1;
String sendString="WellCome you to connect to me!";
OutputStream sout;
DataOutputStream dos;

InputStream sint;
DataInputStream dis;

try
{
s=new ServerSocket(1234);
}
catch(IOException e){}
while(true){
try{
s1=s.accept();
sout=s1.getOutputStream();
dos=new DataOutputStream(sout);
dos.writeUTF(sendString);

sint=s1.getInputStream();
dis=new DataInputStream(sint);
String st=new String(dis.readUTF());
System.out.println(st);//就是这里不能打印出客户端的信息“I am client !");”

sout.close();
s1.close();
}
catch(IOException e){}
}

}
}
---------------------------------------------------------------
客户端:
import java.net.*;
import java.io.*;
public class SimpleClient
{
public static void main(String agrs[]) throws IOException
{
int c;
Socket s1;
InputStream istr;
OutputStream ostr;
DataInputStream distr;
DataOutputStream dostr;
s1=new Socket("ruanwq",1234);
istr=s1.getInputStream();
distr=new DataInputStream(istr);
String st=new String(distr.readUTF());
System.out.println(st);

ostr=s1.getOutputStream();
dostr=new DataOutputStream(ostr);
dostr.writeUTF("I am client !");

ostr.close();
istr.close();
s1.close();
}
}
...全文
136 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
good_speed 2001-07-22
  • 打赏
  • 举报
回复
好熟悉的程序,不知道在哪里看到过
rwq_ 2001-07-22
  • 打赏
  • 举报
回复
把分送了吧!
rwq_ 2001-07-22
  • 打赏
  • 举报
回复
哈哈,今天又可以了!谢谢各位!
rwq_ 2001-07-22
  • 打赏
  • 举报
回复
但服务器端 发送的信息客户端可以收到!,我想问题应该是客户端的发送部分出问题!
masterz 2001-07-22
  • 打赏
  • 举报
回复
可以发的
可能是这一句
s1=new Socket("ruanwq",1234);//你要吧ruanwq改为你的计算机的名字就好了
rwq_ 2001-07-22
  • 打赏
  • 举报
回复
是SL-275培训教材的简单的网络连接程序例子(变量我改了,和功能也改了)!

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧