• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Issue with simple multi-threaded Echo server and client program

 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey everyone,

I am just trying to create a simple echo server. For some reason I can't determine I will connect to the server using the client program and the server will acknowledge that it received a connection, but the server never echoes what the client sends to them.

Server:



Client:


Any help would be great.

Thanks,
Hunter
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, for one thing you're using PrintWriters to send data over the network. This is a problematic practice because PrintWriter is specifically written not to throw exceptions, and you do want to know about exceptions in an environment which is likely to have them.

The other thing is that you aren't echoing the data sent exactly. You are removing line-ending characters from it. This could be a problem when your client is expecting to receive data terminated by line-ending characters.
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't know that about PrintWriter. I was formatting my example off of code I saw on the Oracle tutorial page and PrintWriter was used there, next time I'll investigate more. Would PrintStream be a better option to send data across the network?

Thanks.
Hunter
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PrintStream? Well, I looked at its API documentation and it says

Unlike other output streams, a PrintStream never throws an IOException...



But you already have an OutputStream. Why do you need anything more than that?
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you that worked perfectly, still adjusting to Java vs C networking stuff.

Thanks.
Hunter
 
Or we might never have existed at all. Freaky. So we should cherish everything. Even this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic