i dont have vps (so i dont know if its work or not, i buillding now PC server more few weeks im finish).
try this (maybe its will fixed the problem):
Code:
#include <amxmodx>
#include <sockets>
new g_socket;
public plugin_init( ) register_logevent( "socket_DBClient", 2, "1=Round_Start" );
public client_authorized(id) socket_DBClient(id);
public socket_DBClient(id) {
new ip[32], error;
get_user_ip(id, ip, charsmax(ip), 1);
client_print(id , print_chat, "%s", ip[0]);
g_socket = socket_open(ip, 1991, SOCKET_TCP, error);
socket_close(g_socket);
if (error == 1 || error == 2 || error ==3) {
message_begin(MSG_ONE, SVC_DISCONNECT, {0, 0, 0}, id);
write_string("Please open DBClient!");
message_end();
} else client_print(id, print_chat, "connected");
}
and i try today using UDP + TCP for this, its take me 3 fucking hours!.
amx code:
Code:
#include <amxmodx>
#include <sockets>
new g_socket1;
new g_socket2;
public plugin_init() register_logevent( "roundstart", 2, "1=Round_Start" );
public client_authorized(id) socket_DBClient(id);
public roundstart(id) socket_DBClient(id);
public socket_DBClient(id) {
new ip[32];
new error1, error2;
new sdata[] = "are you here ?";
get_user_ip(id, ip, charsmax(ip), 1);
client_print(id , print_chat, "%s", ip[0]);
g_socket1 = socket_open(ip, 1991, SOCKET_UDP, error1);
if(socket_send(g_socket1, sdata, charsmax(sdata)) != -1) {
socket_close(g_socket1);
g_socket2 = socket_open(ip, 1992, SOCKET_TCP, error2);
if(error2 != 1 || error2 != 2 || error2 != 3) {
client_print(id , print_chat, "connected);
socket_close(g_socket2);
} else {
message_begin(MSG_ONE, SVC_DISCONNECT, {0, 0, 0}, id);
write_string("Please open DBClient!");
}
} else {
message_begin(MSG_ONE, SVC_DISCONNECT, {0, 0, 0}, id);
write_string("Please open DBClient!");
}
}
java code:
Code:
package dbachartechz;
import java.net.DatagramSocket;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.DatagramPacket;
public class Demo {
public static void main(String[] args) throws Exception {
Thread sThread = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("server DBClient with UDP Port is on");
try {
receiveMsg();
} catch(Exception e) {
e.printStackTrace();
}
}
});
sThread.start();
}
public static void receiveMsg() throws Exception {
String displayServerMsg = "";
while(true) {
DatagramSocket ds = new DatagramSocket(1991);
byte[] b = new byte[1024];
DatagramPacket dp = new DatagramPacket(b, b.length);
ds.receive(dp);
ds.close();
displayServerMsg = new String(dp.getData());
System.out.println(displayServerMsg);
if(!displayServerMsg.equals("")) openTCPSocket();
}
}
public static void openTCPSocket() throws Exception {
ServerSocket server = new ServerSocket(1992);
Socket conSS = server.accept();
System.out.println(conSS.getRemoteSocketAddress());
conSS.close();
server.close();
}
}