aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes PC Connected to Internet and Internet Connectivity? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "PC Connected to Internet and Internet Connectivity?" Watch "PC Connected to Internet and Internet Connectivity?" New topic
Author

PC Connected to Internet and Internet Connectivity?

J. Insi
Ranch Hand

Joined: Aug 11, 2010
Posts: 90
Greetings everyone!
in this early morning about 6.27am, i got questioned about how the socket programming works.
And yet, I found tons of discussion here and there about it.
But, again, with a minimum of experience regarding about the networking stuff, here
I wanted to ask you guys... perhaps you already know rather than me.
I'm still seeking answer through google and other forum, tough.

okay, suppose, this PC is already connected through Internet.
And a user open up browser Internet Explorer for example.
And how could we implement a Java Application, running
and listening to the incoming response?

Should I use proxy or something?
But how java could have smthg like filtering here?

I came across from other respond,
and then My friend told me "Try to implement a single thread, and active thread using serverSocket...
Listening to some specific port."
but again, i have a limited shade of lightness here.

~ I need advice.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

What is it that you want to achieve specifically?
J. Insi
Ranch Hand

Joined: Aug 11, 2010
Posts: 90
to obtain the incoming HTTP Response...
at the time user browsing the internet using the internet browser


... anyone may suggest me a couple thing exact to it?
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

I don't think you can intercept the response when you're using another program as the browser.

I think that if you want the response from the website, you will have to access it through your Java application itself. Is this still acceptable for your requirements?
J. Insi
Ranch Hand

Joined: Aug 11, 2010
Posts: 90
okay that's the deal, Stephan van Hulst.

I just figured it out here.
Eventhough, my work still not completed yet.

If you ever noticed at the Windows Environment
there's an Internet Option, and also Proxy server there.
(I.E user also may noticed about this)

Why dont we bind our ServerSocket into it (proxy server)?
Instead of putting the outsider IP Address as Proxy Server,
why dont we use the localhost (our self) as proxy server, and of course
using a different port opened.

Thus, the response from INTERNET (outsiders) would eventually going through
our ServerSocket first, then showed to the browser...

i was thinking this way.... how could that be, Stephan van Hulst?


you will have to access it through your Java application itself. Is this still acceptable for your requirements?


nope. that's not what we want it.
to access outside (INTERNET) via browser, common browser.
Not the java app as browser.
J. Insi
Ranch Hand

Joined: Aug 11, 2010
Posts: 90
and yes, i'm sure.
after reading a bit



Now, what i need now is how to setup the proxy server in java
so when it runs, it will make itself as filtering apps
by obtaining the response from outside...
and again bind it to our localhost...

if there's anyone know about this already,
please post up some suggestion...
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Well, you have a pointer to Muffin, right there, which is an excellent proxy server written in Java. It can be customized by writing your own filters in Java, so you can use it to do whatever it is you want to do.


[Jess in Action][AskingGoodQuestions]
J. Insi
Ranch Hand

Joined: Aug 11, 2010
Posts: 90
well to be honest, Ernest Friedman-Hill.
I also found out some suggestion from my friend telling me,
you need to use two socketServer 1 on 80 port and another one socketServer 2 as a proxy port (customizable; example 3000).


And then, he pointed to me that these need to be in a separated thread (running), thus each of them are communicating
as a well proper internet filter.

But that one makes me confused even more.
By having two socketServer at the same time? I said to him.

And he replied me.
Well, yes. Even in a single file it doesnt matter. What the main concern is that this pc used, is connected to internet.
And the Internet Option is using Proxy Server to be enabled... and it's bind to 127.0.0.1
Which means the proxy is himself (127.0.0.1:3000)


And then I asks my self whetherthis is possible?
That the Browser would eventually talk with the proxy first then to the outside (internet)...?

He eventually talking to me that...
But remember the inputstream and outputstream need to be coupled with those socketservet running without end.


Huuuh?
Now I become more confused.


J. Insi
Ranch Hand

Joined: Aug 11, 2010
Posts: 90
o gosh....

I found a lack understanding while
opening the muffin source code (zip)

does anyone have idea about this?


actually, would it be possible if let say
1 pc using socket open to the internet,
and another socket open to the local browser?

please review this image

Uploaded with ImageShack.us

I was thinking that the proxy server should be applied locally
but different than the port 80.

J. Insi
Ranch Hand

Joined: Aug 11, 2010
Posts: 90



i tried to implement this algorithm but it's unsufficient for making a local proxy server
as a filtering app.

Please review if anyone may do it here;


1) Initiate serverSocket
2) iterate looping without end, do accepting input
3) create the socket receiving the input request
4) read in the buffer-in from socket received, get the destination address
5) pass the address obtained (http://something.com) to url object
6) make HttpURLConnection supplied by url object created previously
7) write the buffer out from the buffer-out



again, i said this one is insufficient.
Since it's just taking in and out the requested data of Http
and the result is, the page obtained may be seen on the browser
without any image retrieved, or no css retrieved.


gosh!
J. Insi
Ranch Hand

Joined: Aug 11, 2010
Posts: 90

thanks for everyone !

now I made it!
The concept i used is that made 1 serversocket opened.
And then create one more socket to communicate with the real server.
Thus the serversocket would received the real respond from real server
after the socket get inputstream previously...



Now, I'm sure I can do for solving out this thread.
But seems the problem occured is that the bytes transferred is never been closed.

please take a look


J. Insi
Ranch Hand

Joined: Aug 11, 2010
Posts: 90


he-he-he.
The previous source code I just posted was the 2nd version,
that I tried to make.

And great, this is the 1st version of the source code.
This one is quite... more suffer (if i'm not mistaken).
Since it can't handle the streaming properly.

But sometimes it do filtering, and blockout the content of the web visited.
Anyway, if there's a suggestion in terms of the algorithm...
you may post up here.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PC Connected to Internet and Internet Connectivity?