2
votes

I'm trying to write a simple server application that listens on a port for XMPP connections from clients, but the application does not seem to open the port.

Here is what I tried so far:

Server.java

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Collection;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; 
import javax.security.auth.callback.*;    
import org.jivesoftware.smack.*;

public class Server implements Runnable{

    private static final int DEFAULT_PORT = 5222;
    private XMPPTCPConnection connection;
    private ExecutorService serv;
    public Server() {
        connection = new XMPPTCPConnection(new ConnectionConfiguration("localhost",DEFAULT_PORT));
        serv = Executors.newCachedThreadPool();
        XMPPTCPConnection.addConnectionCreationListener(new ConnectionCreationListener() {

            public void connectionCreated(XMPPConnection arg0) {

                serv.submit(new ClientWorker((XMPPTCPConnection) arg0));
            }

        });
        connection.addConnectionListener(new ServerListener());
    }
    public void run() {
        while(true)
        {
        }
    }

}

ServerListener is a class that implements ConnectionListener and ClientWorker is a class that implements Runnable.

I searched on Google but I can't find any example for server applications using smack library, only for client applications. Can you please tell what am I doing wrong?

1

1 Answers

2
votes

Smack is a XMPP Client library. It provides no means and is not meant to run a XMPP Server.