Originally posted by Dragon Liu:
Hi hotsoup:
If you have the source code of ServerSocket,you can see when the
Serversocket receive your request datagram,what does it deal with
it.Maybe The ServerSocket close right now without send data to you when receive your datagram.
In vc the socket is more complex than socket in java.
In fact,the serversocket has send the data to me.And when I use
Delphi or VB as the clientsocket,I can get the data from the serversocket.No problem!
So I don't think the serversocket is wrong.I can give you my source code , check it please!Thank you.
Importance:"client_in.read(cbuf)"
public class H2Sock
{
private BufferedReader client_in ;
private PrintStream client_out;
private Socket sock;
//
public H2Sock(){
try{
sock = new Socket("redhat",8009);
sock.setSoTimeout(5000);
DataOutputStream cl_out= new DataOutputStream(sock.getOutputStream());
client_out=new PrintStream(cl_out);
client_in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
}catch(Exception e)
{
System.out.println("Error:"+e);
}
}
//
public H2Sock(
String host,int port){
try{
sock = new Socket(host,port);
sock.setSoTimeout(5000);
DataOutputStream cl_out= new DataOutputStream(sock.getOutputStream());
client_out=new PrintStream(cl_out);
client_in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
}catch(Exception e)
{
System.out.println("Error:"+e);
}
}
public void Send(String sendStr)
{
try{
String overFlag = "\u001a";
String sendPackage = sendStr + overFlag;
client_out.println(sendPackage);
client_out.flush();
System.out.println("SendSuccess!");
}catch(Exception e){
System.out.println("SendError:"+e);
}
}
public Vector Accept()
{
String result = "";
Vector resultBuf = new Vector();
char cbuf[] = new char[20480];
try{
client_in.read(cbuf);
int bufLen = lenOfbuf(cbuf);
System.out.println("Length :"+bufLen);
boolean more = true;
int index = 0;
while(more)
{
result = result + cbuf[index];
if(index == bufLen-1)
more = false;
if(index == 79){
resultBuf.add(result);
result = "";
}
index ++;
}
resultBuf.add(result);
}catch(Exception e){
System.out.println("AcceptError:"+e);
}
return resultBuf;
}
}