I
I
IsaevDev2015-06-26 12:59:05
CMS
IsaevDev, 2015-06-26 12:59:05

What is the problem of connecting to java server?

There is a vps with Linux Centos 6.5 I
run a simple java echo server on it. I tried to listen to different ports - 2525, 7070, 8080
Through iptables I opened tcp and udp connections to these ports, and icmp type 8
I start the server from su
I check the ping of the server - it's normal
Next I try to connect via flash from my site and via telnet from the command line
The situation is as follows - the server starts without errors, the axis writes that java is hanging on the right port, flash sends packets.
But there is no connection to the remote server through flash or telnet. Java does not write anything to the console either.
And everything works on localhost via telnet
Three days in Google did not produce results
. What could be the problem?
UPD: runserver
[[email protected] SocketServer]# java -classpath . Server
SERVER :: started ServerSocket[addr=0.0.0.0/0.0.0.0,localport=8080]
SERVER :: wait for client
UPD: iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A INPUT -i eth0 -p tcp -m tcp --dport 843 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 2525 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 7070 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A INPUT -p udp -m udp --dport 8080 -j ACCEPT
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
UPD: server.class

import java.io.*;
import java.net.*;

public class Server {

  public static void main(String[] args) throws IOException {
    BufferedReader in = null;
    PrintWriter    out= null;

    ServerSocket servers = null;
    Socket       fromclient = null;

    // create server socket
    try {
      servers = new ServerSocket(8080);
      System.out.println("SERVER :: started "+servers);
    } catch (IOException e) {
      System.out.println("SERVER :: couldn't listen to port 8080");
      System.exit(-1);
    }

    try {
      System.out.print("SERVER :: wait for client");
      fromclient= servers.accept();
      System.out.println("SERVER :: client connected");
    } catch (IOException e) {
      System.out.println("SERVER :: can't accept");
      System.exit(-1);
    }

    in  = new BufferedReader(new 
     InputStreamReader(fromclient.getInputStream()));
    out = new PrintWriter(fromclient.getOutputStream(),true);
    String         input,output;

    System.out.println("SERVER :: wait for messages");
    while ((input = in.readLine()) != null) {
     if (input.equalsIgnoreCase("exit")) break;
     out.println("S ::: "+input);
     System.out.println(input);
    }
    System.out.println("SERVER :: end of session");
    out.close();
    in.close();
    fromclient.close();
    servers.close();
  }
}

UPD: multithreaded server.class
import java.io.*;
import java.net.*;
import java.lang.Thread;
 
public class EchoServer {
  public static void main (String[] args) {
    try {
      ServerSocket server = new ServerSocket(8080, 0, InetAddress.getByName("server_ip"));
      //ServerSocket server = new ServerSocket(8080); ТАКЖЕ НЕ РАБОТАЕТ

      System.out.println("SERVER :: created "+server);
      while (true) {
        Socket client = server.accept();
        System.out.println("SERVER :: got client");
        EchoHandler handler = new EchoHandler(client);
        handler.start();
      }
    }
    catch (Exception e) {
      System.err.println("SERVER :: Exception caught:" + e);
    }
  }
}
 
class EchoHandler extends Thread {
  Socket client;
  EchoHandler (Socket client) {
    this.client = client;
  }
 
  public void run () {
    try {
      BufferedReader reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
      PrintWriter writer = new PrintWriter(client.getOutputStream(), true);
      writer.println("SERVER :: [type 'bye' to disconnect]");
 
      while (true) {
        String line = reader.readLine();
        if (line.trim().equals("bye")) {
          writer.println("SERVER :: bye!");
          break;
        }
        writer.println("SERVER :: [echo] " + line);
      }
    }
    catch (Exception e) {
      System.err.println("SERVER :: Exception caught: client disconnected.");
    }
    finally {
      try { client.close(); }
      catch (Exception e ){ ; }
    }
  }
}

UPD: netstat -an | grep "LIST"
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0 .0.1:25 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:47200 0.0.0.0:* LISTEN
tcp 0 0 :::111 :::* LISTEN
tcp 0 0 :::22 :::* LISTEN
tcp 0 0 ::1:631 :::* LISTEN
tcp 0 0 :::51934 :::* LISTEN
unix 2 [ ACC ] STREAM LISTENING 12215 @/var/run/hald/dbus-avqOESAjSU
unix 2 [ ACC ] STREAM LISTENING 12016 /var/run/dbus/system_bus_socket
unix 2 [ ACC ] STREAM LISTENING 8871 @/com/ubuntu/upstart
unix 2 [ ACC ] STREAM LISTENING 12208 @/var/run/hald/dbus-HwJ9Avx459
unix 2 [ ACC ] STREAM LISTENING 12093 /var/run/cups/cups.sock
unix 2 [ ACC ] STREAM LISTENING 11653 /var/run/rpcbind.sock
unix 2 [ ACC ] STREAM LISTENING 12171 /var/run/acpid.socket
unix 2 [ ACC ] STREAM LISTENING 12783 public/cleanup
unix 2 [ ACC ] STREAM LISTENING 12790 private/tlsmgr
unix 2 [ ACC ] STREAM LISTENING 12794 private/rewrite
unix 2 [ ACC ] STREAM LISTENING 12798 private/bounce
unix 2 [ ACC ] STREAM LISTENING 12802 private/defer
unix 2 [ ACC ] STREAM LISTENING 12806 private/trace
unix 2 [ ACC ] STREAM LISTENING 12810 private/verify
unix 2 [ ACC ] STREAM LISTENING 12814 public/flush
unix 2 [ ACC ] STREAM LISTENING 12818 private/proxymap
unix 2 [ ACC ] STREAM LISTENING 12822 private/proxywrite
unix 2 [ACC] STREAM LISTENING 12826 private/smtp
unix 2 [ ACC ] STREAM LISTENING 12830 private/relay
unix 2 [ ACC ] STREAM LISTENING 12834 public/showq
unix 2 [ ACC ] STREAM LISTENING 12838 private/error
unix 2 [ ACC ] STREAM LISTENING 12842 private/retry
unix 2 [ ACC ] STREAM LISTENING 12846 private/discard
unix 2 [ ACC ] STREAM LISTENING 12850 private/local
unix 2 [ ACC ] STREAM LISTENING 12854 private/virtual
unix 2 [ ACC ] STREAM LISTENING 12858 private/lmtp
unix 2 [ ACC ] STREAM LISTENING 12862 private/anvil
unix 2 [ACC] STREAM LISTENING 12866 private/scache
unix 2 [ ACC ] STREAM LISTENING 12949 /var/run/abrt/abrt.socket

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
X
xmoonlight, 2018-10-03
@xmoonlight

I do not see the connection between CMS and data for the database.
I work with CMS Joomla! and the Helix3 template.
Everything suits me there: a lot of modules and little coding (for default projects, such as a blog, business cards, etc.).

O
ocatoll, 2018-10-04
@ocatoll

What data is in your database? What will users do with them? Just text or will there be some calculations? What loads are expected?
How many fields per item? If we talk about Drupal, for example, then you may encounter the problem of the maximum number of joins in mysql, if you really have a lot of fields, and you will attach them all to the node.
In general, you need more information about your task in order to decide on the engine. I would advise you to use the same yii if possible.

A
Azazel PW, 2015-06-26
@IsaevDev

iptables -S can you show?

M
Moxa, 2015-06-26
@Moxa

what interface is the server listening on? maybe it waits for connections only locally?

P
protven, 2015-06-26
@protven

Well, run tcpdump on the server on this port and open the resulting dump in wireshark. A ruble for a hundred, the problem is in your flush.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question