Why am I getting "java.net.BindException: Address already in use: NET_Bind" error?
My code is below:
public ServerSocket server = null;
public static void run() throws
FileNotFoundException{
PrintWriter logFile = new
PrintWriter("C:OutFile.log.txt");
var date = new
java.util.Date();
var nDate = date.toString();
try {
ServerSocket ss = new
ServerSocket(1234);
Socket s = ss.accept();
//log connection time
logFile.printf("Got a Connection:
", nDate);
//listen on 2nd socket
ServerSocket nn = new
ServerSocket(2345);
Socket n = nn.accept();
//log connection time
logFile.printf("Got a Connection:
", nDate);
DataInputStream dataIn = new
DataInputStream(s.getInputStream());
DataOutputStream dataOut = new
DataOutputStream(s.getOutputStream());
String str =
dataIn.readUTF();
String cstr=null;
// loop exit when it find "quit" in
input
while(!str.equals("quit")) {
cstr =
CipherServer.PoyAlphabet.cipher(cstr);
dataOut.writeUTF(cstr);
dataOut.flush();
str = dataIn.readUTF();
}
dataOut.writeUTF("Good
Bye!");
s.close();
ss.close();
//log disconnect time
logFile.printf("Connection Closed:
", nDate);
logFile.close();
} catch (IOException e) {
// TODO Auto-generated catch
block
e.printStackTrace();
}
}
java.net.BindException: Address already in use: in Java occurs because you are trying to access a port which is already in use by another program. In your case the port number 2345 you have used might be being used by another program.
So one easy solution is to change the port number in both the places in your program and try again. For example try with another port number 73501 etc.
Another solution is to find out the program which is using the port you are using and kill that program. This will leave the port free for your use.
In windows to find out which program is using the port you require open the command program by pressing windows key and typing cmd to open command prompt. Then use command netstat -ano | find "2345"
In linux use the command netstat -nap | grep 2345
Note that even a previous instant of your own program might be running in another command prompt which is preventing you from accessing the port.
Even simply restarting the system can sometimes solve the issue if the program is not a startup program.
Why am I getting "java.net.BindException: Address already in use: NET_Bind" error? My code is below: public...
Error: Main method not found in class ServiceProvider, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application This is the error im getting while executing the following code Can you modify the error import java.net.*; import java.io.*; public class ServiceProvider extends Thread { //initialize socket and input stream private Socket socket = null; private ServerSocket server = null; private DataInputStream in = null; private DataOutputStream out = null; private int...
I am working on this code and keep getting errors like "ERROR: Syntax error: Encountered "<EOF>" at line 1, column 169." and "ERROR: Table/View 'STUDENT' does not exist. ERROR: Table/View 'STUDENT' does not exist. ERROR: Table/View 'STUDENT' does not exist." I do not know why this isn't working. Here is my code: DTCCDatabase.java import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; /** * This program creates the CoffeeDB database. */ public class DTCCDatabase { public static void main(String[] args)...
Need Help ASAP!! Below is my code and i am getting error in
(public interface stack) and in StackImplementation class. Please
help me fix it. Please provide a solution so i can fix the
error.
thank you....
package mazeGame;
import java.io.*;
import java.util.*;
public class mazeGame {
static String[][]maze;
public static void main(String[] args)
{
maze=new String[30][30];
maze=fillArray("mazefile.txt");
}
public static String[][]fillArray(String file)
{
maze = new String[30][30];
try{...
I have to modify a server program and chat program to work as the following instructions but I am completely clueless as to where to start. I'd appreciate any help on how to atleast get started. This must be done in java. Diffie-Hellman Two parties use a key agreement protocol to generate identical secret keys for encryption without ever having to transmit the secret key. The protocol works by both parties agreeing on a set of values (a) and (q)....
I cant get the code to work. Any help would be appreciated. Instruction.java package simmac; public class Instruction { public static final int DW = 0x0000; public static final int ADD = 0x0001; public static final int SUB = 0x0002; public static final int LDA = 0x0003; public static final int LDI = 0x0004; public static final int STR = 0x0005; public static final int BRH = 0x0006; public static final int CBR = 0x0007; public static final int HLT...