Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: creating mysql proxy

  1. #1
    Junior Member shadihrr's Avatar
    Join Date
    Jan 2010
    Location
    home
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default creating mysql proxy

    Hi everybody

    I want to read mysql connection info with java. For example I made a server socket with java on port 4444. Then I made a jdbc driver with url "jdbc:mysql://127.0.0.1:4444/mysql". My mysql is running on port 3306.
    I wrote something like below in client class:
        Connection c = DriverManager.getConnection(CONNECTION,p);
    which CONNECTION is "jdbc:mysql://127.0.0.1:4444/mysql"

    and in server I have this:
    clientSocket = ss.accept();
    the server get the clientSocket but "clientSocket.getInputStream().available()" is 0.
    I really don't know how to fix this problem. I have to know which database, client wants to connect and also I don't want to change the client's source code.
    I then wrote this in server class, hope this would solve the problem, but it didn't work
    Connection c = DriverManager.getConnection(CONNECTION,p);
    				    ObjectOutputStream oo=new ObjectOutputStream(clientSocket.getOutputStream());
    				    oo.writeObject(c);
    Maybe the way I fix the problem is wrong. if it is, please help me how to write a proxy server for my database


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: creating mysql proxy

    Does the client send any data to the server? I recommend posting an SSCCE to demonstrate.

  3. #3
    Junior Member shadihrr's Avatar
    Join Date
    Jan 2010
    Location
    home
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: creating mysql proxy

    Does the client send any data to the server? I recommend posting an SSCCE to demonstrate.
    I don't know if SSCCE has a special format or not. But here is the example:
    client sends a request for connecting to a database server: for example at localhost:4444
    My server runs at localhost:4444. It should get the data client sends and if it is OK, It passes it to the real database server which is running at localhost:3306.
    (exactly like firewall for database)
    I think client just open a socket and as I said the "clientSocket.getInputStream().available()" is 0. So I don't think it sends anything to server
    again maybe the way I used is wrong and I don't know what to do about it.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: creating mysql proxy

    Again, does the client send any data? I probably wouldn't rely on the available method anyway (at least in the context you provided) - what if the order of events is that a) server accepts the socket b) checks for available c) client sends data - the server will not find available() to be greater than 0. Instead, try reading from the InputStream - it will block until data is available or an exception is thrown.

    See the link in my signature for the definition of SSCCE

  5. #5
    Junior Member shadihrr's Avatar
    Join Date
    Jan 2010
    Location
    home
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: creating mysql proxy

    yes that is exactly what happened. Server is block until the client sends something and it doesn't send anything so the server is block for ever. I don't want this. I want to read the packages that client sends in order to connect to database (something like sniffing). I don't know maybe "DriverManager.getConnection" wants something before it sends anything.
    If I shouldn't rely on available method, how can I understand if client sends anything or not?
    I will send SSCCE later.

Similar Threads

  1. proxy ip send post request
    By rojersjoo in forum Java Networking
    Replies: 1
    Last Post: February 17th, 2012, 12:10 AM
  2. Simple Proxy Server, Bypassing. Help
    By jrdncchr in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 4th, 2011, 11:24 AM
  3. [SOLVED] Proxy authentication
    By jaya in forum Java Networking
    Replies: 2
    Last Post: January 27th, 2011, 04:04 AM
  4. Replies: 0
    Last Post: January 17th, 2011, 05:14 AM
  5. get proxy settings from the default system browser
    By reguapo in forum Java Networking
    Replies: 0
    Last Post: January 15th, 2010, 08:43 AM