Every time when i try to catch exception on the rage of my port
Also the Message input box ( can't enter the negative number )
The program seems like doesn't response for my action
but when i disable all the code below it will work fine
Here is code
private void connetButtonActionPerformed(java.awt.event.ActionEvent evt) {
String servName = serverField.getText();
int servPort = Integer.valueOf(portTextField.getText());
request = messageField.getText();
//
// try{ // Define Area of port that using
//
// int servPort = Integer.valueOf(portTextField.getText());
//
// request = messageField.getText();
//
// int i = Integer.parseInt(request);
// if(i<0){
// JOptionPane.showMessageDialog(null, "Could not Enter A Negative Integer!");
// }
// if(servPort > 10000 && servPort < 65536){
//
// }else{
// JOptionPane.showMessageDialog(null, "Port Number Must Be Between 10001 to 65535");
// }
//
// }
// catch(NumberFormatException e){
// JOptionPane.showMessageDialog(null, "Port Number Must Be Only Interger");
//
!!!!! This Area seem like it doesn't work for my program
///////////////////////////////////////////////////////////////////////////////////////////
DatagramSocket soc = null;
try { // socket that is going to be send PLUS Set time out 3 sec
soc = new DatagramSocket();
} catch (SocketException ex) {
JOptionPane.showMessageDialog(null, "Fill The Gap DAMMIT !");
}
try {
soc.setSoTimeout(3000);
} catch (SocketException ex) {
JOptionPane.showMessageDialog(null,"TIME OUT!");
}
InetAddress IPAddress = null;
try {
IPAddress = InetAddress.getByName(servName);
} catch (UnknownHostException ex) {
JOptionPane.showMessageDialog(null,"Unknow Exception");
}
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];
sendData = request.getBytes();
int servPort = Integer.valueOf(portTextField.getText());// but if i put this the line below is going to work however Nothing will send to the server
DatagramPacket sendPacket = new DatagramPacket(sendData,sendData.length, IPAddress, servPort); // This line is gonna to be red line if i catch the exception above
try {
soc.send(sendPacket);
} catch (IOException ex) {
JOptionPane.showMessageDialog(null,"");
}
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
try {
soc.receive(receivePacket);
} catch (IOException ex) {
Logger.getLogger(netInterface.class.getName()).log(Level.SEVERE, null, ex);
}
}
plz give me some advice