Hello, I have some java code that just doesn't seem to be working properly, and I'm not sure why.
I'll post the segment, and then explain what's happening.
if (e.getSource() == startButton)//starting server
{
String temp1;
temp1 = JOptionPane.showInputDialog(
"What port do you want the server to listen to?");
sLog.append("Starting server on port: " + temp1 + newline
+ "Awaiting Connection." + newline);
try
{
port = Integer.parseInt(temp1);
}
catch (NumberFormatException NFExc)
{
sLog.append("Incorrect input: port must be a number" + newline);
startButton.setEnabled(true);
stopButton.setEnabled(false);
}
try
{
serverSkt = new ServerSocket(port);
}
catch (IOException err)
{
sLog.append("Error creating a socket on port " + port + newline);
} // end try
while (true)
{
try
{
s = serverSkt.accept();
...
out = s.getOutputStream();
in = s.getInputStream();
...
}
catch (IOException err)
{
...
}
This is within my action listener. sLog is a Jtext area on a JScrollPane, yadda yadda yadda. I get no errors or warnings at compile. When I run the app, and I click the button to start the server, it goes into the action listener (I've traced through the steps) the showInputDialog asks and properly stores the port #, but the "sLog.append" does not show up on the window, the port is properly converted to an int, and then the server stops at the "s = serverSkt.accept();" as it should (accept is a blocking command).
The problem is, I don't ever successfully connect. Now, if I comment out the while(true), the accept, and any use of s, everything works just fine (sans the network connection, of course).
Any ideas? I will be eternally grateful... or at least I'll be grateful until I get busy again.
I'll post the segment, and then explain what's happening.
if (e.getSource() == startButton)//starting server
{
String temp1;
temp1 = JOptionPane.showInputDialog(
"What port do you want the server to listen to?");
sLog.append("Starting server on port: " + temp1 + newline
+ "Awaiting Connection." + newline);
try
{
port = Integer.parseInt(temp1);
}
catch (NumberFormatException NFExc)
{
sLog.append("Incorrect input: port must be a number" + newline);
startButton.setEnabled(true);
stopButton.setEnabled(false);
}
try
{
serverSkt = new ServerSocket(port);
}
catch (IOException err)
{
sLog.append("Error creating a socket on port " + port + newline);
} // end try
while (true)
{
try
{
s = serverSkt.accept();
...
out = s.getOutputStream();
in = s.getInputStream();
...
}
catch (IOException err)
{
...
}
This is within my action listener. sLog is a Jtext area on a JScrollPane, yadda yadda yadda. I get no errors or warnings at compile. When I run the app, and I click the button to start the server, it goes into the action listener (I've traced through the steps) the showInputDialog asks and properly stores the port #, but the "sLog.append" does not show up on the window, the port is properly converted to an int, and then the server stops at the "s = serverSkt.accept();" as it should (accept is a blocking command).
The problem is, I don't ever successfully connect. Now, if I comment out the while(true), the accept, and any use of s, everything works just fine (sans the network connection, of course).
Any ideas? I will be eternally grateful... or at least I'll be grateful until I get busy again.
