JMeter has a global namespace and thread-specific namespaces.  Seems to
me you would want to store your socket in the thread-specific namespace,
and any TCP Sampler can retrieve it from there.  Each one should also be
able to create a new one if it does not yet exist, and at test end, the
sampler should make sure to clean it out (implement TestListener).

To access the thread-specific storage area:

JMeterContextService.getContext().getVariables().putObject
("sharedSocketReference",sharedSocket);

and

JMeterContextService.getContext().getVariables.getObject
("sharedSocketReference")

Calling these methods guarantees you are only talking to the current
thread's storage space.

-Mike

On Thu, 2005-07-21 at 13:22 +0100, srikanth peddireddy wrote:
> Hi Sebb,
> 
> can you please answer some more questions on this topic. I gave some of my 
> assumptions and dopubts below your response 
> 
> >>The current TCP Sampler creates a new socket for each sampler
> >>occurrence in each thread. I do plan to add re-usable sockets to the
> >>TCP Sampler, but that probably won't be for a few weeks.
> 
> First I planned to extend the TCPsampler by myself and though of a design 
> like this :
>     There will be a specialized TcpSampler(for discussion lets call it 
> SharedTcpSampler) . Instances of this SharedTcpSampler will be used for all 
> the TCP requests that we want to make to a server over a single 
> connection/socket.
>   This SharedTcpSampler will have a property called "sharedSocketReference" 
> which will be something like a reference name that we give to a global 
> counter inorder to use it else where in testplan.
>   Each SharedTcpSampler will first try to get the socket instance by 
> searching for it in a Global NameSpace (Iam yet to know what this Global Name 
> Space would be in Jmeter context) by giving the "sharedSocketReference" value 
> that user will configure in testplan. 
> 
> If this search is successful,( ie some other SharedTcpSampler  in the 
> testplan has already created a socket connection and registered it under this 
> name), then it will send its "Text To send" (inherited from TcpSampler) over 
> that socket and reads back the response.
> 
> If this search fails , which will be the case with first SharedTcpSampler in 
> the testplan , it will create a new socket and register it in a Global 
> NameSpace under the name specified in "sharedSocketReference" and continues 
> using it for implmenting the protocol
> 
> So in this solution, all the SharedTcpSamplers in a testplan with same value 
> given in their  "sharedSocketReference" property will share a single socket 
> connection. Hence I think it will serve the purpose.
> 
> But I know that inorder to implement this I need to know the architecture of 
> Jmeter and different components of it in detail. I was unable to study this 
> any further as I was tied to some other work. :-(
> Sebb, can you please tell me whether this design fits the bill. If yes please 
> direct me towards some resources thru which I can quickly learn about 
> architecture and components of Jemter and implement this.
> Iam planning to do this as soon as possible. :-)
> 
> >>One way to re-use the same socket might to have only a single sampler,
> >>and vary the content of the request using a function call to read it
> >>from a file.
> 
> can you eloborate on this or tell me about the resources where I can find 
> details.
> 
> >>However, I've not tried this.
> 
> 
> ==
> 
> >>Note that the TCPSampler class is the one that creates the socket. The
> >>TCPClientImpl class uses the socket to implement the protocol.
> 
> >>The current protocol sends the string as is, and reads bytes until the
> >>EOL byte is seen. EOL can be defined by the property tcp.eolByte.
> 
> In my application all server responses end with a "5". 
> We achive this by appending (char)5 at the end to the String to be sent .
> 
> like         String txtTosend = "some data "+(char)5  
> 
>                stream.write(txtTosend.getBytes());
> 
> 
> So now can I give 5 for  tcp.eolByte so that Jmeter reads entire response 
> string/data ???
> 
> 
> ==
> 
> >>JMeter is built around the assumption of a request/response sample.
> 
> >>There's currently no provision for reading from a socket without
> >>previously writing to it, but that would be trivial to add - I may
> >>well add that to the nightly code shortly. Or indeed it may already
> >>work if you provide an empty string.
> 
> >>But the test plan would have to include samplers for each expected
> >>server response.
> 
> >>If a single client request results in a known number of responses, or
> >>there is some other way of telling that the server has finished
> >>responding to the original request, then the TCPClientImpl read()
> >>method could implement this.
> 
> can you eloborate on this or tell me about the resources where I can find 
> details.
> S.
> > 
> 
> 
> Regards
> 
> Srikanth.P
> 
> 
> Disclaimer
> ------------------------------------------------------------------------------------
> This e-mail message may contain confidential, proprietary 
> or legally privileged information. It should not be used by
> anyone who is not the original intended recipient. If you
> have erroneously received this message, please delete it
> immediately and notify the sender. 
> 
> The views, opinions, conclusions and other information 
> expressed in this electronic mail are those of the 
> individual sender and not endorsed by SDG Software 
> Technologies Pvt. Ltd. unless otherwise indicated by an 
> authorised representative independent of this message.
> 
> Before opening any attachment please check them for viruses 
> and defects. SDG Software Technologies Pvt. Ltd. shall not 
> accept responsibility for any loss or damage arising from 
> the use of this email or attachment(s).
> -------------------------------------------------------------------------------------
>               
> ---------------------------------
> How much free photo storage do you get? Store your friends n family photos 
> for FREE with Yahoo! Photos. 
>  http://in.photos.yahoo.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to