File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Writing bytes out to a socket Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Writing bytes out to a socket" Watch "Writing bytes out to a socket" New topic
Author

Writing bytes out to a socket

Sally Molloy
Greenhorn

Joined: Mar 01, 2012
Posts: 6
Hi,
I am a compete greenhorn, no in fact that is probably being a bit generous. I am many years in software but have never even taken a single class in Java, just the way it happened - it didn't come up.
Now I am taking night course in security and the very lazy, arrogant lecturer won't accept the assignments in anything other than Java although "this is not a Java course" as he keeps telling us. So yes people this is homework, just not Java homework.
I need to write a client that takes in user input (string) opens a socket and sends it off as bytes to the server.
Through Googling and general hacking together of examples I have it compiled and talking to the server I was provided with but the server keeps producing an error claiming I am sending ASCII.
Everything I read, including on this site suggests I am sending the string converted to bytes....
Can anyone suggest what is going on??
I am literally begging for help on this one.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

What exactly do you mean the server "keeps producing an error claiming I am sending ASCII."?

Also, when you catch an exception, at the very least, print the stack trace. (That's not actually proper exception handling either, but at least you get to see details of the problem, and for educational exercises it's often good enough.)


Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Also, if you're just echoing text back and forth, why are you messing around with Data Streams and ByteArray Streams?
Sally Molloy
Greenhorn

Joined: Mar 01, 2012
Posts: 6
Hi Jeff, thanks for replying.


I think I have left out some critical points in my explanation of what I am trying to do!
* I have to write to a server thats been provided as an executable so pretty much black box.
* The user is to enter any string when running the client and indicates end of entry by hitting return
* The client is expecting to receive this string as a byte array or byte stream??
* The server is outputting messages like "invalid type 48 in stream, expected 1". In the bit of blurb provided with the server this is listed as a common error and says you are still sending a string, not bytes???

Thanks for the advice onthe exceptions - I have changed that now but I am not seeing any output as I amn't encountering an exception
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing bytes out to a socket