I'm trying to develop a class that sends email using the SMTP protocol, without using any libraries that facilitate sending mail, such as MimeMessage or MailUtility.
This is what I've done so far:
public class MailSender {
protected String localMachine;
protected String localSMTPServer;
private String textMail;
private String mailFrom;
public MailSender(String localSMTPServer, String mailFrom) {
try {
this.textMail = "null";
this.localSMTPServer = localSMTPServer;
this.mailFrom = mailFrom;
InetAddress localIP = InetAddress.getLocalHost();
this.localMachine = localIP.getHostAddress();
} catch (UnknownHostException ex) {
Logger.getLogger(MailSender.class.getName()).log(Level.SEVERE, null, ex);
}
}
//getter and setter
public void smtp(String command) {
try {
System.out.println(sIn.readLine());
os.write((command + "\n").getBytes());
System.out.println("end");
} catch (IOException ex) {
System.out.println(ex);
Logger.getLogger(MailSender.class.getName()).log(Level.SEVERE, null, ex);
}
}
BufferedReader sIn;
OutputStream os;
public Boolean trySend(String destUser, String subject, String message) {
Socket socket;
try {
socket = new Socket(localSMTPServer, 587);
OutputStreamWriter sOutW = new OutputStreamWriter(socket.getOutputStream(), "ASCII");
PrintWriter sOut = new PrintWriter(sOutW, true);
InputStreamReader sInR = new InputStreamReader(socket.getInputStream(), "ASCII");
sIn = new BufferedReader(sInR);
os = socket.getOutputStream();
this.nextSMTPCode(sIn, 220);
sOut.println("EHLO");
this.nextSMTPCode(sIn, 250);
sOut.println("AUTH LOGIN");
this.nextSMTPCode(sIn, 250);
sOut.println("xxxxxxxxxxxxxxx=="); //username
sOut.println("xxxxxxxxxxxxxx="); //password
this.nextSMTPCode(sIn, 250);
sOut.println("MAIL FROM: <" + this.mailFrom + ">");
this.nextSMTPCode(sIn, 250);
sOut.println("RCPT TO: <" + destUser + ">");
this.nextSMTPCode(sIn, 250);
sOut.println("DATA");
this.nextSMTPCode(sIn, 250);
sOut.println("From: " + this.mailFrom);
sOut.println("To: " + destUser);
sOut.println("Subject: " + subject);
sOut.println(message);
sOut.println(".");
this.nextSMTPCode(sIn, 250);
sOut.println("QUIT");
this.nextSMTPCode(sIn, 250);
sIn.close();
textMail = "From " + this.mailFrom + " To " + destUser + "\n" + "Subject: " + subject + "\nMessage: " + message;
return true;
} catch (IOException ex) {
Logger.getLogger(MailSender.class.getName()).log(Level.SEVERE, null, ex);
}
return false;
}
public String getMail() {
return textMail;
}
private void nextSMTPCode(BufferedReader sIn, int expectedCode) throws IOException {
int code;
String str = sIn.readLine();
System.out.println(str);
String sCode = str.substring(0, 3);
code = Integer.parseInt(sCode);
if (code != expectedCode) {
sIn.close();
System.out.println("Code: " + code + " expected code was: " + expectedCode);
throw new IOException();
}
}
}
I am having problem with communication with the SMTP server (I am using smtp2go as the server).
The problem is that I keep getting the 250 code even when this shouldn't show up, finally the email isn't sent.
This is a sample communication:
220 mail.smtp2go.com ESMTP Exim 4.96-S2G Tue, 10 Jan 2023 14:42:02+0000
250-mail.smtp2go.com Hello [xxxxx]
250-SIZE 52428800
250-8BITMIME
250-DSN
250-PIPELINING
250-PIPECONNECT
250-AUTH CRAM-MD5 PLAIN LOGIN
250-CHUNKING
I then get 250-SIZE 52428800 and the other responses (always with the code 250) for every command I send. I tried to telnet and everything seems to work, the problem is in my code, but I can't figure out what I'm doing wrong.
Does anyone know the cause of this problem?
SMTP can have multiline responses, but you only expect singleline responses. Multiline responses are typical for EHLO. To cite from RFC 5231:
The format for multiline replies requires that every line, except the last, begin with the reply code, followed immediately by a hyphen, "-" (also known as minus), followed by text. The last line will begin with the reply code, followed immediately by <SP>, optionally some text, and <CRLF>. As noted above, servers SHOULD send the <SP> if subsequent text is not sent, but clients MUST be prepared for it to be omitted.
For example:
250-First line
250-Second line
250-234 Text beginning with numbers
250 The last line
Related
I have an assignment that requires me to build a very basic mail client to send an email on my school's server. If I open a command prompt on my computer and run telnet with these exact commands, the message goes through, but something in the program is causing it to kick back an error message. The exact response is:
451 4.5.0 SMTP protocol violation, see RFC 2821 e127si46647995qkb.26 - gsmtp
Here is the part of my code where I believe the issue to lie:
private void sendMessage(String from, String to, String subject, String msg) {
Socket socket = null;
DataOutputStream os = null;
DataInputStream is = null;
try {
socket = new Socket("ALT3.ASPMX.L.GOOGLE.COM", 25);
os = new DataOutputStream(socket.getOutputStream());
is = new DataInputStream(socket.getInputStream());
} catch (Exception e) {
System.out.println(e);
}
if (socket != null && os != null && is != null) {
try {
os.writeBytes("HELO\n");
os.writeBytes("MAIL From: <" + from + ">\n");
os.writeBytes("RCPT TO: <" + to + ">\n");
os.writeBytes("DATA\n");
os.writeBytes("From: <" + from + ">\n");
os.writeBytes(subject);
os.writeBytes(msg); // message body
os.writeBytes("\n.\n");
os.writeBytes("QUIT");
String responseLine;
while ((responseLine = is.readLine()) != null) {
System.out.println("Server: " + responseLine);
if (responseLine.indexOf("Ok") != -1) {
break;
}
}
I am trying to create a simple socket based server/client communication between a Java-based socket server and PHP-based socket client. I am getting all the responses as expected but not immediately. Here is what I am trying to do. PHP client sends a command to the Java server, it responds back with an answer. This answer should be displayed on PHP page immediately. Then a second command is sent and again, the server sends a response which should be displayed immediately. However in my case, the responses are 'echoed' only after entire socket based communication is terminated. That is after I close the socket connection from PHP client.
Following is my Java Socket Server code:
public class MultiThreadServer implements Runnable {
Socket csocket;
MultiThreadServer(final Socket csocket) {
this.csocket = csocket;
}
private static void download(final String url) {
try {
final URL downloadURL = new URL(url);
URLConnection conn = null;
try {
conn = downloadURL.openConnection();
final InputStream inputStream = conn.getInputStream();
final long filesize = conn.getContentLength();
System.out.println("Size of file : " + (filesize / 1024)
+ " (kb)");
final FileOutputStream outputStream = new FileOutputStream(
System.getProperty("user.dir") + "/test.exe");
final long startTime = System.currentTimeMillis();
final byte[] buffer = new byte[1024];
int bytesRead = -1;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
final long endTime = System.currentTimeMillis();
System.out.println("File downloaded");
System.out.println("Download time in sec. is : "
+ ((endTime - startTime) / 1000));
outputStream.close();
inputStream.close();
} catch (final IOException e) {
e.printStackTrace();
}
} catch (final MalformedURLException e) {
e.printStackTrace();
}
}
public static void main(final String args[]) throws Exception {
final ServerSocket ssock = new ServerSocket(3333);
System.out.println("Listening on " + ssock.toString());
while (true) {
final Socket sock = ssock.accept();
System.out.println("Connected to " + sock.getRemoteSocketAddress());
new Thread(new MultiThreadServer(sock)).start();
}
}
#Override
public void run() {
try {
final BufferedReader br = new BufferedReader(new InputStreamReader(
this.csocket.getInputStream()));
final BufferedWriter bw = new BufferedWriter(
new OutputStreamWriter(this.csocket.getOutputStream()));
bw.write(this.csocket.getRemoteSocketAddress().toString()
.replace("/", "")
+ "\n");
bw.flush();
String line;
while ((line = br.readLine()) != null) {
if (line.equalsIgnoreCase("getMacName")) {
final String macName = InetAddress.getLocalHost()
.getHostName();
bw.write(macName + "\n");
bw.flush();
System.out.println("Machine Name : " + macName);
} else if (line.equalsIgnoreCase("getMacIP")) {
final String macIP = InetAddress.getLocalHost()
.getHostAddress();
bw.write(macIP + "\n");
bw.flush();
System.out.println("Machine IP : " + macIP);
} else if (line.equalsIgnoreCase("getCurrentVersion")) {
final String currVersion = "0.1a";
bw.write(currVersion + "\n");
bw.flush();
System.out.println("Current Version : " + currVersion);
} else if (line
.equalsIgnoreCase("downUrl:http://webserver/webapp/test.exe")) {
final String url = line.substring(8);
bw.write("Downloading : " + url + "\n");
bw.flush();
MultiThreadServer.download(url);
System.out.println("URL : " + url);
} else if (line.equalsIgnoreCase("exit")) {
bw.write("Closing\n");
bw.flush();
bw.close();
br.close();
System.out.println("Exiting!");
this.csocket.close();
break;
}
}
} catch (final IOException e) {
e.printStackTrace();
}
}
}
Following is my sample PHP client source code:
<html>
<head>
<title>Socket Connection Test</title>
</head>
<body>
<h3>Testing Socket Connection</h3>
<br>
<?php
$host="127.0.0.1";
$port = 3333;
$fp;
$macName;
$macIP;
$message;
$result;
// open a client connection
$fp = fsockopen ($host, $port, $errno, $errstr);
if (!$fp)
{
$result = "Error: Could not open socket connection! Error No: " . $errno . ". Error String: " . $errstr;
die($result);
}
else
{
$message = fgets ($fp, 1024);
$message = trim($message);
echo "Connected to remote server on current port : " . $message;
echo "<br>";
sleep(5);
// get machine name
fwrite ($fp, "getMacName\n");
$macName = fgets ($fp, 1024);
$macName = trim($macName);
echo "Machine Name : " . $macName;
echo "<br>";
sleep(5);
// get IP address
fwrite ($fp, "getMacIP\n");
$macIP = fgets ($fp, 1024);
$macIP = trim($macIP);
echo "Machine IP : " . $macIP;
echo "<br>";
sleep(5);
fwrite ($fp, "getCurrentVersion\n");
$currVersion = fgets ($fp, 1024);
$currVersion = trim($currVersion);
echo "Current Version : " . $currVersion;
echo "<br>";
sleep(5);
fwrite ($fp, "downUrl:http://webserver/webapp/text.exe\n");
$downResponse = fgets ($fp, 1024);
$downResponse = trim($downResponse);
echo "Download Response : " . $downResponse;
echo "<br>";
sleep(5);
fwrite ($fp, "exit\n");
$exitStatus = fgets ($fp, 1024);
fclose ($fp);
echo "Connection Closed.";
}
?>
</body>
</html>
In this case, the entire PHP output is displayed at the end. I even tried putting sleeps at various places, however it seems to be waiting for socket connection to be closed before writing the output. How can I can I get the output "LIVE". Like a normal chat communication? What am I doing wrong here?
Your script works okay, and has no big flaws for what you're looking for. Since you obtain the desired result when you run the script from command line rather than a web browser, we can pinpoint the cause of the issue: the HTTP protocol
HTTP isn't made for sustained connections (like you're used to with Java sockets) but it's simplified workflow is based along the lines of Request/Elaborate/Response/Forget. Therefore, you can't have a "live chat" with a pure HTML/PHP over HTTP solution.
Alas, not all your hopes are lost! To implement a "live" communication you can use Ajax, which isn't too hard to get used to. I've said "live" because it's still an HTTP based solution, but at least you can have requests and receive responses from within the same webpage, which is the closest you can get with the HTML/PHP/AJAX triad.
It seems you dont understand php with http well .
You will get the HTML response only after your php client code completes execution. (i.e) all your echo's will be put in place where you specified and returned as a whole.
Putting sleep will only delay the execution.
Okay, the following are 2 classes that I am using in creating a simple TFTP (Trivial File Transfer Protocol) program. I am running a server instance and a client instance of this program. What I am trying to accomplish is this:
The client connects to the server and sends a message of a specific file that it wants. The server locates the file and sends a response (either a 1 or 0... 1 meaning the file is there, and 0 meaning that it is not). Then the server will send the content of the file to the client application. The files I am trying to send are just simple text files.
Right now, I am able to receive the name of the text file that the client wants, but then when I go to send back the response, I am not getting anything returned. Also below are the methods that the server and the client both run.
This is the server instance
SwingUtilities.invokeLater(new Runnable(){
public void run(){
String fileRequest = UDPReceiver(SERVER_PORT_NUMBER);
outputArea.append("\n" + "File Requested: " + fileRequest + "\n");
outputArea.append("Determining if file exists...\n");
String checkFile = SHARED_DIR + "\\" + fileRequest;
outputArea.append("Checking location: " + checkFile + "\n");
boolean check = fileCheck(checkFile);
if(check == true){
outputArea.append("File location verified..." + "\n");
outputArea.append("Initiating transfer...." + "\n\n");
UDPSender(CLIENT_HOSTNAME, CLIENT_PORT_NUMBER, "1");
}
else{
outputArea.append("File does not exist..." + "\n");
outputArea.append("Exiting run..." + "\n");
}
}
});
The client instance.
SwingUtilities.invokeLater(new Runnable(){
public void run(){
UDPSender(SERVER_HOSTNAME, SERVER_PORT_NUMBER, FILE_REQUEST);
String message = UDPReceiver(CLIENT_PORT_NUMBER);
outputArea.append("\n\n" + message + "\n");
if(message == "1"){
// File exists
outputArea.append("\n");
outputArea.append("File verified..." + "\n");
outputArea.append("Transfer initiated..." + "\n");
}
else{
// File doesn't exist
outputArea.append("\n");
outputArea.append("File does not exist..." + "\n");
outputArea.append("Terminating connection...");
}
}
});
Here are the Sender and Receiver methods.
private void UDPSender(String hostname, String port, String message){
DatagramSocket socket = null;
try{
// Create a datagram socket, look for the first available port
socket = new DatagramSocket();
outputArea.append("Using local port: " + socket.getLocalPort() + "\n");
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
PrintStream pOut = new PrintStream(bOut);
pOut.print(message);
// Convert printstream to byte array
byte[] bArray = bOut.toByteArray();
// Create a DatagramPacket, containing a maximum buffer of 256 bytes
DatagramPacket packet = new DatagramPacket(bArray, bArray.length);
outputArea.append("Looking for hostname " + hostname + "\n");
// Get the InetAddress object
InetAddress remote_addr = InetAddress.getByName(hostname);
// Check its IP Number
outputArea.append("Hostname has IP Address = " + remote_addr.getHostAddress() + "\n");
// Configure the DatagramPacket
packet.setAddress(remote_addr);
packet.setPort(Integer.parseInt(port));
// Send the packet
socket.send(packet);
outputArea.append("Packet sent at: " + new Date() + "\n");
// Display packet information
outputArea.append("Sent by: " + remote_addr.getHostAddress() + "\n");
outputArea.append("Sent from: " + packet.getPort() + "\n");
socket.close();
}
catch(UnknownHostException ue){
outputArea.append("Unknown host: " + hostname + "\n");
outputArea.append("Unknown host: " + ue + "\n");
}
catch(IOException e){
outputArea.append("Error: " + e + "\n");
}
}
private String UDPReceiver(String portNum){
String message = "";
DatagramSocket socket = null;
try{
// Create a DatagramSocket
socket = new DatagramSocket(Integer.parseInt(portNum));
outputArea.append("Listening on local port " + socket.getLocalPort() + "\n");
// Create a DatagramPacket, containing a maximum buffer of 256 bytes
DatagramPacket packet = new DatagramPacket(new byte[256], 256);
// Receive a packet - remember by default this is a blocking operation
socket.receive(packet);
outputArea.append("Packet received at " + new Date() + "\n");
// Display packet information
InetAddress remote_addr = packet.getAddress();
outputArea.append("Sender: " + remote_addr.getHostAddress() + "\n");
outputArea.append("From Port: " + packet.getPort() + "\n");
CLIENT_HOSTNAME = remote_addr.getHostAddress();
//CLIENT_PORT_NUMBER = Integer.toString(packet.getPort());
// Display packet contents, by reading from byte array
ByteArrayInputStream bin = new ByteArrayInputStream(packet.getData());
// Display only up to the length of the original UDP packet
for(int i = 0; i < packet.getLength(); i++){
int data = bin.read();
if(data == -1){
break;
}
else{
message = message + (char)data;
//outputArea.append(Character.toString((char)data));
}
}
socket.close();
return message;
}
catch(IOException e){
outputArea.append("Error: " + e + "\n");
message = "Error: " + e;
return message;
}
}
Any help that you folks can offer would be greatly appreciated. The main thing I am trying to figure out is how to be able to get the server and client to be able to send messages back and forth. Thanks in advance guys.
EDIT:
I am also getting an error now in Netbeans when I run this project. I think it has something to do with this line of code in the UDPReceiver method:
socket = new DatagramSocket(Integer.parseInt(portNum));
But I can't figure out what is wrong with that.
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:454)
at java.lang.Integer.parseInt(Integer.java:527)
at tftp_gui.main.UDPReceiver(main.java:508)
at tftp_gui.main.access$800(main.java:20)
at tftp_gui.main$10.run(main.java:374)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
you approach is wrong, as it is requires opened client port, anyway your particular problem is because you're not sending back result when file is not found:
check:
if(check == true){
outputArea.append("File location verified..." + "\n");
outputArea.append("Initiating transfer...." + "\n\n");
UDPSender(CLIENT_HOSTNAME, CLIENT_PORT_NUMBER, "1");
}
else {
outputArea.append("File does not exist..." + "\n");
outputArea.append("Exiting run..." + "\n");
UDPSender(CLIENT_HOSTNAME, CLIENT_PORT_NUMBER, "0"); // here you should send 0
}
also, you have small problem here: if(message == "1") it should look like if ("1".equals(message))
Your error is self explainable - you're haven't declared proper CLIENT_PORT_NUMBER or SERVER_PORT_NUMBER, here is what I've used for testing:
private final static String SERVER_PORT_NUMBER = "1234";
private static String CLIENT_HOSTNAME;
private static final String CLIENT_PORT_NUMBER = "2345";
private static final String FILE_REQUEST = "a.txt";
private static final String SHARED_DIR = "d:/";
private static final String SERVER_HOSTNAME = "localhost";
I'm doing a ftp file download from a server with help from an Apache library (commons.net ver 3.2). The download was fine and I received all the file that I needed and saved them in a folder. The problem that I have is with the timeouts because when the connection is interrupted while I'm downloading I need an error message that shows me that the connection has been lost, but I have found difficulties doing this, I have searched countless forums including this one and I have tried many ways to solve this but no one have result yet! The code that I have is as follows:
public void doSomething(String ip, int port, String user, String pass, String server, String remotePath, String localPath) {
int tenseconds = 10 * 1000;
int thirtyseconds = 30 * 3000;
Socket s4 = new Socket();
java.net.InetSocketAddress adr = new java.net.InetSocketAddress("213.0.17.234", 21);
s4.connect(adr, thirtyseconds);
FTPClient client = new FTPClient();
org.apache.commons.vfs2.FileSystemOptions fileSystemOptions = null;
String key = FtpFileSystemConfigBuilder.getInstance().getEntryParser(fileSystemOptions);
try {
client.setConnectTimeout(tenseconds);
client.setDefaultTimeout(thirtyseconds);
client.connect(ip, port);
client.setSoTimeout(thirtyseconds);
int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
throw new FileSystemException("vfs.provider.ftp/connect-rejected.error");
}
client.enterLocalPassiveMode();
boolean login = client.login(user, pass);
URL url = new URL("ftp://" + user + ":" + pass + "#" + server + remotePath + ";type=i");
URLConnection urlc = url.openConnection();
urlc.setConnectTimeout(1000);
InputStream is = urlc.getInputStream();
BufferedWriter bw = new BufferedWriter(new FileWriter(localPath));
int c;
client.setSoTimeout(tenseconds);
client.setControlKeepAliveTimeout(10000);
while ((c = is.read()) != -1) {
urlc.getConnectTimeout();
bw.write(c);
}
long t2 = System.currentTimeMillis();
System.out.println(t2);
JOptionPane.showMessageDialog(null, "se cargo el primer fichero!", "información", JOptionPane.INFORMATION_MESSAGE);
if (login) {
FTPFile[] files = client.listFiles();
for (FTPFile file : files) {
if (file.getType() == FTPFile.DIRECTORY_TYPE) {
System.out.println("ftp file: " + file.getName() + ";" + FileUtils.byteCountToDisplaySize(file.getSize()));
} else if (file.getType() == FTPFile.FILE_TYPE) {
System.out.println("ftp file: " + file.getName() + ";" + FileUtils.byteCountToDisplaySize(file.getSize()));
}
}
is.close();
bw.close();
client.setSoTimeout(tenseconds);
client.logout();
client.disconnect();
}
} catch (IOException e) {
StringWriter sw0 = new StringWriter();
PrintWriter p0 = new PrintWriter(sw0, true);
e.printStackTrace(p0);
System.out.println("connection probably lost");
JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
I have tried all the things a could find a have read that the setdefaulttimeout is used to activate all the timeouts, connectiontiomeout is used to wait for connections and getsotimeouts is used when we are downoading a file but it doesn't work I have tried give it 5 seconds so it will not download the file but it doesn't work, I have read that there are some issues whit connectiontimeouts and that we should use socketfactory, so I creaded a socket factory as well and I tried but it didn't work and I have reach a point where I'm a little bit desperade so I´m asking you for help I all so tried client.setControlKeepAliveTimeout(10000); to establish an alive timeout but it didn't work! :(
i'm trying to convert a simple irc client written on java to blackberry, it uses sockets, here it is:
package seinao;
import java.io.*;
import java.net.*;
public class Client {
public static void main(String[] args) throws Exception {
// The server to connect to and our details.
String server = "127.0.0.1";
String nick = "nickname";
String login = "nickname";
// The channel which the bot will join.
String channel = "#oi";
// Connect directly to the IRC server.
Socket socket = new Socket(server, 6667);
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(socket.getOutputStream( )));
BufferedReader reader = new BufferedReader(
new InputStreamReader(socket.getInputStream( )));
// Log on to the server.
writer.write("NICK " + nick + "\r\n");
writer.write("USER " + login + " 8 * : Java IRC Hacks Bot\r\n");
writer.write("Hello World!");
writer.write("PRIVMSG " + channel + "Hello!\r\n");
writer.flush( );
// Read lines from the server until it tells us we have connected.
String line = null;
while ((line = reader.readLine( )) != null) {
if (line.indexOf("004") >= 0) {
// We are now logged in.
break;
}
else if (line.indexOf("433") >= 0) {
System.out.println("Nickname is already in use.");
return;
}
}
// Join the channel.
writer.write("JOIN " + channel + "\r\n");
writer.flush( );
// Keep reading lines from the server.
while ((line = reader.readLine( )) != null) {
if (line.toLowerCase( ).startsWith("PING ")) {
// We must respond to PINGs to avoid being disconnected.
writer.write("PONG " + line.substring(5) + "\r\n");
writer.write("PRIVMSG " + channel + " :I got pinged!\r\n");
writer.flush( );
}
else if(line.toLowerCase( ).contains("funciona")){
writer.write("PRIVMSG " + channel + " Olaz!\r\n");
writer.flush();
System.out.println("mermao ta foda");
}
else {
// Print the raw line received by the client.
System.out.println(line);
}
}
}
}
but i noticed there is no java.net.* on blackberry eclipse plugin soo, what should I do ? can someone help me ? what should I use for sockets ? I'm new to java and blackberry programming but i'm learning it quite fast, thanks alot
If I remember correctly, it's SocketConnection that you use. Search through the Blackberry API for what you'll need, it'll be way more helpful.