高手们指点一下!关于socket、服务器模拟的问题!

tavor 2005-04-24 03:42:31
我用java写了一个简单的服务器程序,用来模拟一个服务器(我没有原来的服务器程序,只能模拟)。

ServerSocket=new ServerSocket(2022,10);
Socket client=ServerSocket.accept();
然后获得一个DataInputStream in 和PrintWriter对象
然后 byte [] t=new byte[];in.read(t);
到read的时候就不走了
可是我用自己写的客户端却可以数据,晕死,指点一下,老大们!

注明:这里的客户端不是用JAVA写的,什么语言写的不清楚,估计是C++
...全文
117 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
007remember 2005-05-10
  • 打赏
  • 举报
回复
呵呵
分嘛,小case啦
关键是问题要解决ye
wzd268 2005-05-10
  • 打赏
  • 举报
回复
楼主莫心疼,千金散尽还复来
关键是做人要厚道,呵呵
tavor 2005-05-10
  • 打赏
  • 举报
回复
晕,问题搞明白了,原来建立连接后,应该是服务器先发送数据,郁闷了,我的100分啊
silverend 2005-04-25
  • 打赏
  • 举报
回复
socket通信与用何种语言应该无关的。
我这有个曾做过的Server端的例子,你看看

import java.net.ServerSocket;
import java.net.Socket;
import java.io.*;

public class ServerSocketIns{
private String receiveMsg = "";
private String sendMsg = "";

public void doListener(int port){
try{
//build connection
ServerSocket server = new ServerSocket(port);
Socket socket = server.accept();
System.out.println( "The server is listenning!" + "\n" ) ;

while(true){
//receive message
InputStream in = socket.getInputStream();
this.receiveMsg = "" ;
int ch ;
while (true){
ch = in.read();
if ((char)ch == '\r')
break;
else
this.receiveMsg += (char) ch;
}

if ( this.receiveMsg.equals( "Quit" ) ) // when quit
System.exit(0);

System.out.println("Receive from The Client :" + this.receiveMsg + "\n" );

this.sendMsg = this.receiveMsg ;

//send message
OutputStream out = socket.getOutputStream();
this.sendMsg += " at Time: " ;
this.sendMsg += (new java.util.Date()).toString();
this.sendMsg += '\r' ;
out.write( this.sendMsg.getBytes() );
out.flush();
System.out.println("The server has resended the message back!" );
System.out.println(this.sendMsg);
System.out.println();
this.sendMsg = "" ;
}
}
catch(IOException e){
e.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
}
}

public static void main(String[] args){
ServerSocketIns ssocket = new ServerSocketIns() ;
ssocket.doListener( 8000 ) ;
}

}
wanghongtaoleifeng 2005-04-25
  • 打赏
  • 举报
回复
都是按照网络传输协议 不会不通吧
MARS.nEIL 2005-04-24
  • 打赏
  • 举报
回复
会不会是客户端与服务器端因为两种使用语言的缘故,所以不能通信呢?
007remember 2005-04-24
  • 打赏
  • 举报
回复

那难啦
学习
帮您顶下先

62,616

社区成员

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

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