Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2007, 11:13 AM
Member
 
Join Date: Jul 2007
Posts: 1
gautam89 is on a distinguished road
UnknownHostException?
Hi,

I'm sorry if this sort of question has been answered before. I've looked through many of the threads pertaining to sockets, but was not able to find where I was going wrong.

I need to create a program that can communicate with another PC on the same LAN network for my computer science project. When I run the client program I get the following error:

Exception in thread "main"
java.net.UnknownHostException: GAUTAM-LAPTOP
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at tcpclient.main(tcpclient.java:12)


I'm running the server program on a laptop with name GAUTAM-LAPTOP. I've configured my router to direct port 1234 (TCP) to GAUTAM-LAPTOP as well.

Below is the server code I am using:

Code:
import java.io.*; import java.net.*; public class tcpserver { public static void main(String args[]) throws Exception { String message; String messageout; ServerSocket ssock = new ServerSocket(1234); while(true) { Socket connsock = ssock.accept(); InputStreamReader instr = new InputStreamReader(connsock.getInputStream()); DataOutputStream outstr = new DataOutputStream(connsock.getOutputStream()); BufferedReader innet = new BufferedReader(instr); message = innet.readLine(); messageout = message.toUpperCase() + "\n"; outstr.writeBytes(messageout); } } }
Below is the client code I am using:

Code:
import java.io.*; import java.net.*; public class tcpclient { public static void main(String[] args) throws Exception { String message; String modifiedmessage; BufferedReader inkbd = new BufferedReader(new InputStreamReader(System.in)); Socket csock = new Socket("GAUTAM-LAPTOP",1234); DataOutputStream out = new DataOutputStream(csock.getOutputStream()); BufferedReader innet = new BufferedReader(new InputStreamReader(csock.getInputStream())); message = inkbd.readLine(); out.writeBytes(message + "\n"); modifiedmessage = innet.readLine(); System.out.println("Server sent :- " + modifiedmessage); csock.close(); } }

Can someone please give me some guidance as to what I am doing wrong and why the error is coming? Also, is there an easier way to implement this - I only need it for communication between computers on the same network.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-02-2007, 06:15 PM
Member
 
Join Date: Aug 2007
Posts: 47
henry_78 is on a distinguished road
I think u have a problem with translating your lap-top name in an IP address..try to modify your hosts file adding an entry with your lap-top name and ip
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 02:38 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org