‏إظهار الرسائل ذات التسميات Server. إظهار كافة الرسائل
‏إظهار الرسائل ذات التسميات Server. إظهار كافة الرسائل

الأحد، 5 يناير 2014

Unable to send data from my server to client

I made a simple chat program where sending data from MyClient to MyServer is working, but when sending data from MyServer to MyClient is not working. So where I'm making mistake?

//This is MyServer program

import java.io.*;

import java.net.*;

public class MyServer{

ServerSocket ss; Socket s; DataInputStream din; DataOutputStream dout;

public MyServer(){

try{ System.out.println("Server START......"); ss=new ServerSocket(9000); s=ss.accept(); System.out.println("Client Connected....."); din=new DataInputStream(s.getInputStream()); dout=new DataOutputStream(s.getOutputStream()); chat(); }catch(Exception e){ System.out.println(e);}

}

public void chat()throws IOException{

String str=" "; do{ str=din.readUTF(); System.out.println("Client Message: "+str); dout.writeUTF("I have recieved ur message:"+str); dout.flush(); }while(!str.equals("stop"));

}

public static void main(String arg[]){

new MyServer();}

}

//This is MyClient program

import java.io.*;

import java.net.*;

public class MyClient{

Socket s; DataInputStream din; DataOutputStream dout;

public MyClient(){

try{ s=new Socket("localhost",9000); System.out.println(s); din=new DataInputStream(s.getInputStream()); dout=new DataOutputStream(s.getOutputStream()); chat(); }catch(Exception e){ System.out.println(e);}

}

public void chat()throws IOException{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String s1;do{ s1=br.readLine(); dout.writeUTF(s1); dout.flush(); System.out.println("Server Message: "+din.readUTF()); }while(!s1.equals("stop"));

}

public static void main(String arg[]){

new MyClient();}

}


View the original article here

الثلاثاء، 24 ديسمبر 2013

Why JDBC cant connect to local Mysql Server

I have a machine with CentOS and mysql server on it (let's call it 'Server'). And another(my desktop) machine with Debian (let's call it 'Desktop'). I tried to launch java program on Desktop machine. Application connects to Server's mysql database without any troubles.

When I finished development of this application (it's still works and connects to DB well) I tried to deploy this app to Server machine. I'v built it the app on the server and tried to launch, using database, which still hosted on Server machine. So now it seems to be local database for my application. But it fails during connection to DB using Server IP address or "localhost" or 127.0.0.1. I have only:

java.sql.SQLException: null, message from server: "Host '82.192.90.179' is not allowed to connect to this MySQL server".

In my.cnf file on Server I've set "bind-address=0.0.0.0".

PS:The most interesting thing, I do everything on server using ssh, and if I try to connect to database with "mysql" console tool, it connects OK either with -h82.192.90.179 and without -h option(seems to be localhost as a dafault)


View the original article here