I am developing small chatting application...
when i try to run the application, it throws the IO Exception while creating sockets..

How to resolve resolve the this one..? please help me..

i attached the code for your view...

That means it couldn't find the destination. I noticed you are using command line args. Do you know how to get those? It won't run unless you have an argument to the right destination.

Hai Server_crash,
What is the another way to obtain that..?
give me a solution...

Another way would be using a bufferedreader to get input from the user. But why not jut compile with the correct arguments? You know how to do that right?

javac ProgramName.java

java ProgramName argument1


did u watch my code..?
In that code, everything is fine and correct..

i am running by this way,
C:\Java>java ExChat aik6 100

ExChat - my Pgm Name
aik6 - my system name..
100 - the port for my socket

but when i run i got the error message...
"IO Exception Error for Creating Socket"..

it doesn't take my system name..thats the problem...
i want to chat with in the same system...

how i modify code...

here, i pasted my code..

import java.lang.System;        
import java.net.Socket;        
import java.net.InetAddress;        
import java.net.UnknownHostException;        
import java.io.*;        
public class ExChat {        
public static void main(String args[]){        
PortTalk portTalk = new PortTalk(args);        
class PortTalk {        
Socket connection;        
DataOutputStream outStream;        
BufferedReader inStream;        
public PortTalk(String args[]){        
if(args.length!=2) error("Usage: java PortTalkApp host port");        
String destination = args[0];        
int port = 0;        
try {        
port = Integer.valueOf(args[1]).intValue();        
}catch (NumberFormatException ex){        
error("Invalid port number");        
connection = new Socket(destination,port);        
}catch (UnknownHostException ex){        
error("Unknown host");        
catch (IOException ex){        
error("IO error creating socket");        
inStream = new BufferedReader(        
new InputStreamReader(connection.getInputStream()));        
outStream = new DataOutputStream(connection.getOutputStream());        
}catch (IOException ex){        
error("IO error getting streams");        
System.out.println("Connected to "+destination+" at port "+port+".");        
public void displayDestinationParameters(){        
InetAddress destAddress = connection.getInetAddress();        
String name = destAddress.getHostName();        
byte ipAddress[] = destAddress.getAddress();        
int port = connection.getPort();        
displayParameters("Destination ",name,ipAddress,port);        
public void displayLocalParameters(){        
InetAddress localAddress = null;        
localAddress = InetAddress.getLocalHost();        
}catch (UnknownHostException ex){        
error("Error getting local host information");        
String name = localAddress.getHostName();        
byte ipAddress[] = localAddress.getAddress();        
int port = connection.getLocalPort();        
displayParameters("Local ",name,ipAddress,port);        
public void displayParameters(String s,String name,        
byte ipAddress[],int port){        
System.out.println(s+"host is "+name+".");        
System.out.print(s+"IP address is ");        
for(int i=0;i<ipAddress.length;++i)        
System.out.println(s+"port number is "+port+".");        
public void chat(){        
BufferedReader keyboardInput = new BufferedReader(        
new InputStreamReader(System.in));        
boolean finished = false;        
do {        
System.out.print("Send, receive, or quit (S/R/Q): ");        
String line = keyboardInput.readLine();        
switch (line.charAt(0)){        
case 'S':         
String sendLine = keyboardInput.readLine();        
case 'R':        
int inByte;        
while ((inByte = inStream.read()) != '\n')        
case 'Q':        
}catch (IOException ex){        
error("Error reading from keyboard or socket");        
} while(!finished);        
public void shutdown(){        
}catch (IOException ex){        
error("IO error closing socket");        
public void error(String s){        

And another one, how i get my ip address and place in the InetAddress...?

pls help me...

Gokulakrishnan.M :-|

Ok so its 9 am...and still no sleep so i wont go thru all this code but just a quick little two cents worth. Its a chat program, the way i normally do these (and there might be others) is to use 2 ports (send / receive) and multiple threads. 1 thread for gui, 1 thread for functionality, and 1 thread for a "ConnectionListener".

The program that is listening for a connection (chat client to connect) needs to create a ServerSocket. e.g. "ServerSocket myServerSocket = new ServerSocket( << a port # >>);"

That port is now locked on your system so unless you start a client (with listener) on a different port you will encounter problems (or at least i did when i wrote my first chat program).

A quick run thru on how i believe ServerSockets work. They listen on a port and when a connection is attempted with "Socket mySocket = MyServerSocket.accept();" it makes a connection (socket) on a port (other then the one being listen upon). Thus if you want to accept multiple connection. e.g. chat with more then 1 person at a time put the code to accept connections in a loop to keep on listening for more connections.

if you dont get this fixed i'll take a look at your code after i get some sleep.

p.s. does "InetAdress.getLocalHost().getHostAddress()" accomplish what you needed for the ip?

Hi everyone,

Your error is due to the fact that you have no server. Read up on sockets and serversockets to improve your skills

Richard West

Can any one help me with a solution to use porttalk.sys to communicate with parallel port

Thank You

lijumon, make your own thread and do not attempt to hijack other threads.

gokul, what is "aik6 - my system name"? It might know how to connect to 'localhost' or an IP address, but unless your home network is setup to recognize aik6 in that manner it probably won't know what the heck that address is.

hey all,
I was also thinking about a chatting application. However I am kinda new to programming. Would someone pliz guide me on how to go about it using C++ or C#(i've gone through the basics of C++). Can the chatting "operation" be achieved by scripting also?

Well, you are off to a good start by choosing to hijack an old thread in the Java forum to ask someone to walk you through it.

Post your question in the C++ or C# forum and don't be surprised if you get very general answers to such a general question.

Thanks. I will try that but about the question being so general I don't really know how specific I can make it, but I will try anyway.

hey all,
I was also thinking about a chatting application. However I am kinda new to programming. Would someone pliz guide me on how to go about it using C++ or C#(i've gone through the basics of C++). Can the chatting "operation" be achieved by scripting also?

If you want to do chat application in C++ or C# you should ask this question in appropriate section of our forum
C++ here
C# here