Lets try to do some dirty way of coding to produce close_wait!
Check out my server code! I am opening up new socket and waiting for request from client!
Once request is received, writing out a message to client and closing the connection then and there!
Server Code
In Client code I am creating new connection with Server and puting the clinet into sleep mode with out closing the connection.
Client Code
This will results as bellow!
Check out my server code! I am opening up new socket and waiting for request from client!
Once request is received, writing out a message to client and closing the connection then and there!
Server Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.net.*; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: vanji | |
* Date: 5/17/13 | |
* Time: 9:31 AM | |
*/ | |
public class Server | |
{ | |
public static void main(String[] args) throws Exception | |
{ | |
Socket socket = new ServerSocket(12345).accept(); | |
OutputStream out = socket.getOutputStream(); | |
out.write("Hello World\n".getBytes()); | |
out.flush(); | |
out.close(); | |
} | |
} |
In Client code I am creating new connection with Server and puting the clinet into sleep mode with out closing the connection.
Client Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.net.*; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: vanji | |
* Date: 5/17/13 | |
* Time: 9:31 AM | |
* To change this template use File | Settings | File Templates. | |
*/ | |
public class Client{ | |
public static void main(String[] args) throws Exception | |
{ | |
Socket socket = new Socket(InetAddress.getByName("localhost"), 12345); | |
InputStream in = socket.getInputStream(); | |
int c; | |
while ((c = in.read()) != -1) | |
{ | |
System.out.write(c); | |
} | |
System.out.flush(); | |
// should now be in CLOSE_WAIT | |
Thread.sleep(Integer.MAX_VALUE); | |
} | |
} |
This will results as bellow!
No comments:
Post a Comment