Results 1 to 2 of 2
- 06-03-2010, 10:35 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 2
- Rep Power
- 0
open a socket to get an image (HELP PLz)
How could i get an image by using TCP connection to open a socket in port 80
My ClientMyServerJava Code:import java.io.*; import java.net.*; public class MyClient { public static void main(String[] args) { Socket newSocket = null; DataOutputStream os = null; DataInputStream is = null; try { newSocket = new Socket("www.google.com", 80); os = new DataOutputStream(newSocket.getOutputStream()); is = new DataInputStream(newSocket.getInputStream()); } catch (UnknownHostException e) { System.err.println("google"); } catch(IOException e){ System.err.println("google"); } if (newSocket != null && os != null && is != null) { try { String responseLine; while ((responseLine = is.readLine()) != null) { System.out.println("Server: " + responseLine); if (responseLine.indexOf("Ok") != -1) { break; } } os.close(); is.close(); newSocket.close(); } catch (UnknownHostException e) { System.err.println("Trying to connect to unknown host: " + e); } catch (IOException e) { System.err.println("IOException: " + e); } } } }
for example if ive been told to open a socket to get the google imageJava Code:import java.io.*; import java.net.*; public class MyServer { public static void main(String args[]) { ServerSocket newServer = null; String line; DataInputStream is; PrintStream os; Socket clientSocket = null; try { newServer = new ServerSocket(80); } catch (IOException e) { System.out.println(e); } try { clientSocket = newServer.accept(); is = new DataInputStream(clientSocket.getInputStream()); os = new PrintStream(clientSocket.getOutputStream()); while (true) { line = is.readLine(); os.println(line); } } catch (IOException e) { System.out.println(e); } } }

in port 80 and it should read
so im still cant fiqure it out how to get the image ??
Any help please
Thanks
- 06-05-2010, 07:32 PM #2
Member
- Join Date
- Jun 2010
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
socket commuication taking 3 minutes to send 512x512 bmp image
By santhosh_el in forum NetworkingReplies: 1Last Post: 10-07-2009, 04:42 PM -
socket communication between c++/java and sending image
By mdemir10 in forum NetworkingReplies: 2Last Post: 09-10-2009, 02:29 PM -
Cannot open socket with Log4J from Applet
By i007 in forum Advanced JavaReplies: 3Last Post: 03-20-2009, 03:01 AM -
Server socket - send image to client
By Hinty in forum NetworkingReplies: 2Last Post: 03-14-2009, 07:39 AM -
How to open a socket through proxy ?
By arnab321 in forum New To JavaReplies: 2Last Post: 03-04-2009, 08:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks