sockets - Java Server and Client Help -


i'm trying write server , client program in java. i've not done before, figured i'ld start examples provided @ links below.

server code: http://java.sun.com/developer/onlinetraining/programming/basicjava2/code/socketserver.java

client code: http://java.sun.com/developer/onlinetraining/programming/basicjava2/code/socketclient.java

i made few changes in terms of naming, basic functionality should same. server app runs fine, client app throwing unknownhostexception. thought problem ip address used in both apps not being valid. i'm running on mac, , don't claim expert on ip addresses, figured might idea write code print out ip address, posted below, in case it's @ helpful.

java.net.inetaddress address = java.net.inetaddress.getlocalhost(); system.out.println("ip address  :"+address.gethostaddress()); 

however, code returns number 463.827.201.789(not demonstrative purposes), doesn't work parameter of socket constructor i'm using.

anyway, don't know issue , need here.

printing inetaddress objects gethostaddress() method prints textual representation of address (as specified in api, check http://download.oracle.com/javase/6/docs/api/java/net/inetaddress.html#gethostaddress()). should ip address of computer? (or possible 127.0.0.1, address points local computer).

the socket class (http://download.oracle.com/javase/6/docs/api/java/net/socket.html) takes inetaddress + port number in constructor should able pass inetaddress , first parameter , port number socketserver listens on. (each server socket opens listener on port number can choose yourself, check http://download.oracle.com/javase/6/docs/api/java/net/serversocket.html).


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -