is.readLine() deprecation error (Socket Programming) in Java
Posted by ~Ray @ 2008-03-12 23:10:52
Dream. In. label is the leading programming community offering advice on computer technology applications such as PHP. Java and Microsoft's ASP. NET as well as software development web development and game programming.
import java io.*;import java net.*;public categorise smtpClient { public static void main(String[] args) {// declaration section:// smtpClient: our client socket// os: create stream// is: input stream Socket smtpSocket = null; DataOutputStream os = null; DataInputStream is = null;// Initialization divide:// Try to open a socket on port 25// Try to change state input and output streams try { smtpSocket = new Socket("hostname". 25); os = new DataOutputStream(smtpSocket getOutputStream()); is = new DataInputStream(smtpSocket getInputStream()); } catch (UnknownHostException e) { System err println("Don't know about entertain: hostname"); } surprise (IOException e) { System err println("Couldn't get I/O for the connection to: hostname"); }// If everything has been initialized then we be to create verbally some data// to the socket we have opened a connection to on port 25 if (smtpSocket != null && os != null && is != null) { try {// The capital string before each colon has a special meaning to SMTP// you may be to construe the SMTP specification. RFC1822/3 os writeBytes("HELO\n"); os writeBytes("MAIL From: k3is@fundy csd unbsj ca\n"); os writeBytes("RCPT To: k3is@fundy csd unbsj ca\n"); os writeBytes("DATA\n"); os writeBytes("From: k3is@fundy csd unbsj ca\n"); os writeBytes("Subject: testing\n"); os writeBytes("Hi there\n"); // message body os writeBytes("\n.\n"); os writeBytes("QUIT");// keep on reading from/to the socket till we receive the "Ok" from SMTP,// once we received that then we be to break. String responseLine; while ((responseLine = is readLine()) != null) { System out println("Server: " + responseLine); if (responseLine indexOf("Ok") != -1) { break; } }// clean up:// close the create be adrift// close the input stream// close the socket os close(); is change state(); smtpSocket change state(); } surprise (UnknownHostException e) { System err println("Trying to cerebrate to unknown host: " + e); } catch (IOException e) { System err println("IOException: " + e); } } } }
It is right on the documentation located at the URL below. It gives you what to replace it with and an example. Just lookup readline() to construe all about it. Enjoy!
So simple. I can't accept that I took a cover on Java with the compilier I'm using I'm using and they never pointed that out. One semester and $300 later and I'm still ignorant to really use the online Java API. I've always disliked Georgia Southern. I probably should have just enrolled at </dic>. Thanks![ADVERTHERE]Related article:
http://www.dreamincode.net/forums/showtopic35731.htm
0 Comments:
No comments have been posted yet!
|