This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

About the Socket connection

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Help!
I used a client socket(java) to connect with a server socket
(VC).I sended a package to server,and when I recieved the ackage ,an error appeared.
"java.netSocketException:JVM_recv in socket input stream read (code=10053)".
I know that it's because of serversocket closing.But I
don't know how to resolve it.
Help!
Thanks a lot.
hotsoup
------------------
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
hotsoup
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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;
}
}

 
Ranch Hand
Posts: 1874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hotsoup , Welcome to javaranch.
PROPER NAMES ARE NOW REQUIRED
Please look carefully at official naming policy at javaranch & reregister yourself with proper first & last name. Please adhere to official naming policy & help maintain the decorum of the forum.
Waiting for your posts with proper first & last name. Once you have reregister , please let us know about that & then your previous account will be disabled.
Regards.

Your Friendly Bartender
Shailesh.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic