Forum Discussion

david_wang_2073's avatar
david_wang_2073
Historic F5 Account
Jul 26, 2005

break long tcp connection

In order to break a long tcp connection with irule, I used a very simple java socket program to do testing, client sends a message to server and server response the message to client. (see attached)

rule testrule1 {
   when CLIENT_ACCEPTED { 
   set count 0
   TCP::collect 
} 
  
when CLIENT_DATA { 
   incr count
   log local0. "count $count"
   if { $count == 2} {
      set count 0
      log local0. "before select nod 11 $count"
      LB::detach
      use node "192.168.2.11" 80
      log local0. "node 11 was selected, count $count"
      TCP::release 
   } else {
      LB::detach
      log local0. "before select pool0 $count"
      pool web_pool
      TCP::release 
   }
}

But when I tried this rule to virtual server, there is no traffic was sent to node.

I just made reference to the irule that break IIOP application to do this, but because these is no document to explain how to use TCP::collect, TCP::release, I can not figure out why my rule can not work.

BTW, in the irule of breaking IIOP, event USER_REQUEST and USER_RESPONSE were used, what they are used for?

when USER_REQUEST {
  if {$c_req_id == 1} {
   set c_req_id 0
   persist add uie $req_id
  }
  if {$c_is_cancel == 1} {
   set c_is_cancel 0
   LB::detach
  }
 }
 when USER_RESPONSE {
  LB::detach
 }
}

Thank you for reply in advance.

/**
class:SocketTest_SvrClit
author:chengyun
date:
with:to test socket---client program;
**/
import java.net.*;
import java.io.*;
public class SocketTest_SvrClit
{
public static void main(String[] args) throws UnknownHostException,IOException,ConnectException
{
Socket aClient=null;
aClient=new Socket("192.168.0.188",3434); //InetAddress.getLocalHost()
try
{
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
BufferedReader in=new BufferedReader(new InputStreamReader(aClient.getInputStream()));
PrintWriter out=new PrintWriter(new OutputStreamWriter(aClient.getOutputStream()));
String clientString=null;
String serverString=null;
int i=1;
System.out.println("hello!enter bye to exit.");
boolean done=false;
serverString="start";
while(!done)
{
if (i==1000) i=1;
Thread.sleep(1000);
//serverString=in.readLine();
if(serverString !=null)
System.out.println("Server:"+serverString);
System.out.print("client:");
//clientString=input.readLine();
clientString=Integer.toString(i++);
if(clientString.equals("bye")) done=true;
if(clientString !=null) 
{
out.println(clientString);
out.flush();
} 
serverString=in.readLine();
}
in.close();
out.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
finally
{
aClient.close();
}
} 
} 
--------------
/**
class:SocketTest_SvrClit
author:chengyun
date:
with:to test socket---server program;
**/
import java.net.*;
import java.io.*;
public class SocketTest_Server
{
public static void main(String[] args) throws UnknownHostException,IOException,ConnectException
{
ServerSocket aServerSocket=new ServerSocket(3434);
Socket aServer=null;
try
{
aServer=aServerSocket.accept();
try
{
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
BufferedReader in=new BufferedReader(new InputStreamReader(aServer.getInputStream()));
PrintWriter out=new PrintWriter(new OutputStreamWriter(aServer.getOutputStream()));
String serverstring=null;
String clientstring=null;
System.out.println("hello! enter the bye to exit.");
System.out.print("Server:wait client");
serverstring=input.readLine();
boolean done=false;
while(!done)
{
if(serverstring !=null)
{
out.println(serverstring);
out.flush();
}
clientstring=in.readLine();
if(clientstring !=null)
System.out.println("client:"+clientstring);
System.out.print("server:");
//serverstring=input.readLine();
serverstring="server:"+clientstring;
if(serverstring.equals("bye")) done=true;
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
finally
{
aServer.close();
} 
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
finally
{
aServerSocket.close();
}
}
}

No RepliesBe the first to reply