Results 1 to 4 of 4
Thread: Simple Socket IOstream problem
- 12-01-2009, 04:43 AM #1
Member
- Join Date
- Sep 2009
- Posts
- 41
- Rep Power
- 0
Simple Socket IOstream problem
ok, I decided to start trying to network for the first time, so I looked up the tutorial and tried out some of the code. I kept running into the IOException that was thrown. I tried to fix it and eventually i just copied and pasted the code into my compiler and I still get the same error caught.
It runs into the IO exception so outputs "Couldn't get I/O for the connection"Java Code:import java.io.*; import java.net.*; public class EchoClient { public static void main(String[] args) throws IOException { Socket echoSocket = null; PrintWriter out = null; BufferedReader in = null; try { echoSocket = new Socket("Alexs-Computer.local", 4321); //echoSocket = new Socket("Alexs Computer", 4321); //echoSocket = new Socket(InetAddress.getLocalHost.getHostName, 4321); //echoSocket = new Socket("10.0.1.5", 4321); out = new PrintWriter(echoSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader( echoSocket.getInputStream())); } catch (UnknownHostException e) { System.err.println("Don't know about host."); System.exit(1); } catch (IOException e) { System.err.println("Couldn't get I/O for " + "the connection"); System.exit(1); } BufferedReader stdIn = new BufferedReader( new InputStreamReader(System.in)); String userInput; while ((userInput = stdIn.readLine()) != null) { out.println(userInput); System.out.println("echo: " + in.readLine()); } out.close(); in.close(); stdIn.close(); echoSocket.close(); } }
Can anyone help me out? Im just trying to get it to run so I can move on!
- 12-01-2009, 06:17 AM #2
maybe "Alexs-Computer.local" is not in the hosts file, or somehow not DNS resolveable into an IP address. Try using your IP address for the machine that the server is running on (e.g. 127.0.0.1)
Also, this is the client that connects to a server right, would you have a server process running and listening on TCP port 4321 in this case ?
- 12-01-2009, 07:42 AM #3
Member
- Join Date
- Sep 2009
- Posts
- 41
- Rep Power
- 0
Alexs-Computer.local I think works too, and i did try 10.0.1.5, I put comments of the other host names, same results for all of them.
So is the problem that I need a server? I didnt know I server for this kind of thing, I was trying to get the basics down. The next section was a server but I didn't want to go on until I got this working!
Edit: Well, I got code for the server from the same place and it too runs into an IOException! Is it something wrong with my computer being able to be a host?Last edited by Atriamax; 12-01-2009 at 07:51 AM.
- 12-01-2009, 08:17 AM #4
Member
- Join Date
- Sep 2009
- Posts
- 41
- Rep Power
- 0
Similar Threads
-
Problem with Java Heap Space using Socket
By mvillara in forum NetworkingReplies: 3Last Post: 08-21-2009, 04:45 AM -
[SOLVED] problem in socket connection
By neeraj.singh in forum NetworkingReplies: 2Last Post: 02-20-2009, 01:33 PM -
problem in socket connection in sending images
By vibhor in forum NetworkingReplies: 2Last Post: 02-20-2009, 05:39 AM -
[SOLVED] Problem with socket programming(Vista)
By jagatsastry in forum NetworkingReplies: 1Last Post: 02-02-2009, 03:56 PM -
Client Server socket problem - help needed
By kellaw in forum Threads and SynchronizationReplies: 6Last Post: 10-03-2008, 06:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks