Results 1 to 4 of 4
Thread: Socket help
- 05-31-2011, 09:08 AM #1
Member
- Join Date
- May 2011
- Posts
- 5
- Rep Power
- 0
Socket help
Hey there,
I am writing this code for a project, but have hit a snag.
Everytime I try to run it it throws a
java.net.ConnectException: Connection refused: connect Exception.
the exception is in this line of code
public void connect(){
try{
//error topline
socket = new Socket(address, Integer.parseInt(port));
out = new ObjectOutputStream(socket.getOutputStream());
in = new ObjectInputStream(socket.getInputStream());
}
catch(Exception ex){
System.out.println("Error connect in ClientSocket" + ex.toString());
}
}
I am trying to connect to a server I have created on the same computer.
this is the code that uses it to connect.
address = location of the database i am trying to connect to (file type .db)
port is a port i enter in a GUI = 1064
try{
if(txtLocation.getText().length() != 0){
setDBLocation(txtLocation.getText());
System.out.println("Sent location to properties" + location);
setPort(txtPort.getText());
ServerSocketClass.register(location, port);
Data data = new Data(location);
MainGUI m = new MainGUI();
m.setVisible(true);
}
else{
msgMessage.showMessageDialog(this, "You need to search for a database.",
"Select a database",
javax.swing.JOptionPane.ERROR_MESSAGE);
this.dispose();
SocketGUI sock = new SocketGUI();
sock.setVisible(true);
}
}
catch(Exception ex){
}
this.dispose();
}
Sorry if I have not explained everything clearly I have been trying to complete this for the last 2weeks and just cant figure out why it throws this exception or what the exception is.
I have tryed turning of my firewalls and security to no prevale.
Thanks
- 05-31-2011, 11:27 AM #2
Straight from the API documentation :
"Signals that an error occurred while attempting to connect a socket to a remote address and port. Typically, the connection was refused remotely (e.g., no process is listening on the remote address/port)."
Read it properly and then crosscheck what might have gone wrong with your code.
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 05-31-2011, 03:08 PM #3
What are the address and port you are using?
Add some printlns to the code to show the values of the variables just before you use them. Before the following lines
socket = new Socket(address, Integer.parseInt(port));
ServerSocketClass.register(location, port);
- 05-31-2011, 03:08 PM #4
Similar Threads
-
Socket and how to launch thread for receiving socket messages
By newbiejava in forum New To JavaReplies: 1Last Post: 07-02-2010, 01:18 PM -
swt socket
By cuiran in forum SWT / JFaceReplies: 2Last Post: 01-22-2010, 01:34 AM -
Socket
By Syahrul in forum New To JavaReplies: 0Last Post: 12-20-2009, 01:31 PM -
append response to the request from Socket and write to another socket
By vaibhav_singh_vs@yahoo.co in forum NetworkingReplies: 3Last Post: 04-17-2009, 07:02 PM -
Socket
By vortex in forum New To JavaReplies: 2Last Post: 05-25-2008, 06:41 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks