• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Unable to continuously send data between tcpserver and tcpclient in java

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My TCP Client does not seems to be able to receive the data send from server after the connection is being accepted by the server.
My TCP Server is seems to be able to received data from client. However after the receiving data from client, the Server seems to be able send back to client (using some filler print statements as check) , but the client just don't seems to be receiving the data from server.
I am new to Java TCP socket programming, could somebody please enlighten me on how to make them work properly. Thanks and Appreciate help given in advance.

Sorry about the long post, as I need to show some critical declarations and part of main code. this is done so that allow others to understand my code better. If this is done correctly, it should look like simple chat program over TCP.

This is my TCP Client Code:


This is my TCP Server Code:
 
Author and all-around good cowpoke
Posts: 13078
6
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. You use a Reader (which tries to make characters) here

but the other code is sending bytes. Socket stuff is vastly simplified by treating everything as bytes.

2. I strongly suggest you do not try to read whole lines with readLine - instead read single bytes and work with them.

Bill


 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
+1 on what William said. Closely related is this issue, which you may be running into: Don't println to a Socket.
 
Sebastian Wong
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

William Brogden wrote:1. You use a Reader (which tries to make characters) here

but the other code is sending bytes. Socket stuff is vastly simplified by treating everything as bytes.

2. I strongly suggest you do not try to read whole lines with readLine - instead read single bytes and work with them.

Bill




Thanks! Your solution solves the problem.
 
I'm THIS CLOSE to ruling the world! Right after reading this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!