I am in networking and did not expect to run into this, this is my code below. I must turn this instant messenger program into an asynchronous communication instant messenger program. What to do to make it to make it asychronous? Here is my code:
import java.io.*;
import java.net.*;
class server
{
public static void main(String[] args)
{
try {
Socket s = (new ServerSocket(2010)).accept();
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
String str = br.readLine();
System.out.println(str);
(new DataOutputStream(s.getOutputStream())).writeBytes( str + "\n");
} catch (IOException e) {
System.out.println(e);
}
}
}
import java.io.*;
import java.net.*;
class client
{
public static void main(String[] args)
{
try {
Socket s = new Socket("localhost", 2010);
(new DataOutputStream(s.getOutputStream())).writeBytes( "Hello, World\n");
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
System.out.println(br.readLine());
} catch (IOException e) {
System.out.println(e);
};
}
}