TCP Sampler- Jmeter

The TCP Sampler opens a TCP/IP connection to the specified server. It then sends the text, and waits for a response.

You can test any Server working over TCP/IP. But In this example I have tested this sampler with a TCP server made in C#. You can download the TCP server here.

http://alokranjan.freehostia.com/codes/TCP%20Server.zip

Steps:
1. Run the TCP server on your system and create a new Test case in Jmeter. The server looks like this before any client connections.

tcp1

2. Add a TCP sampler to the thread group. Fill the fields as follows-

Server name or IP: Localhost
Check reuse connection
Port number: 13000
Timeout: 200
Check Set Nodelay
Text to send: This is the text i hav sent to tcp server

Since there is no login request for the server we leave the username and password field blank.

tcp2

3. Add a listener (View Results tree) and run the test.

tcp3
The sampler result tab gives the response code and load time. The response data shows the data sent by the Server.
You can also check the server whether it has sent the data or not.

tcp4

Advertisements

2 Responses

  1. Friends iam getting this below error while running TCP sampler

    2011/11/29 14:44:41 INFO – jmeter.util.JMeterUtils: Setting Locale to en_US
    2011/11/29 14:44:41 INFO – jmeter.JMeter: Loading user properties from: C:\Documents and Settings\ds111256\Desktop\jmeter-2.3.2\bin\user.properties
    2011/11/29 14:44:41 INFO – jmeter.JMeter: Loading system properties from: C:\Documents and Settings\ds111256\Desktop\jmeter-2.3.2\bin\system.properties
    2011/11/29 14:44:41 INFO – jmeter.JMeter: Copyright (c) 1998-2008 The Apache Software Foundation
    2011/11/29 14:44:41 INFO – jmeter.JMeter: Version 2.3.2 r665936
    2011/11/29 14:44:41 INFO – jmeter.JMeter: java.version=1.6.0_26
    2011/11/29 14:44:41 INFO – jmeter.JMeter: java.vm.name=Java HotSpot(TM) Client VM
    2011/11/29 14:44:41 INFO – jmeter.JMeter: os.name=Windows XP
    2011/11/29 14:44:41 INFO – jmeter.JMeter: os.arch=x86
    2011/11/29 14:44:41 INFO – jmeter.JMeter: os.version=5.1
    2011/11/29 14:44:41 INFO – jmeter.JMeter: file.encoding=Cp1252
    2011/11/29 14:44:41 INFO – jmeter.JMeter: Default Locale=English (United States)
    2011/11/29 14:44:41 INFO – jmeter.JMeter: JMeter Locale=English (United States)
    2011/11/29 14:44:41 INFO – jmeter.JMeter: JMeterHome=C:\Documents and Settings\ds111256\Desktop\jmeter-2.3.2
    2011/11/29 14:44:41 INFO – jmeter.JMeter: user.dir =C:\Documents and Settings\ds111256\Desktop\jmeter-2.3.2\bin
    2011/11/29 14:44:41 INFO – jmeter.JMeter: PWD =C:\Documents and Settings\ds111256\Desktop\jmeter-2.3.2\bin
    2011/11/29 14:44:41 INFO – jmeter.JMeter: IP: 192.168.1.212 Name: BCTCW-Deepakumar FullName: BCTCW-Deepakumar.bctchn.local
    2011/11/29 14:44:41 INFO – jmeter.JMeter: Loaded icon properties from org/apache/jmeter/images/icon.properties
    2011/11/29 14:44:41 INFO – jmeter.engine.util.CompoundVariable: Note: Function class names must contain the string: ‘.functions.’
    2011/11/29 14:44:41 INFO – jmeter.engine.util.CompoundVariable: Note: Function class names must not contain the string: ‘.gui.’
    2011/11/29 14:44:42 INFO – jmeter.protocol.http.sampler.HTTPSamplerBase: Cannot find .className property for htmlParser, using default
    2011/11/29 14:44:42 INFO – jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for text/html is
    2011/11/29 14:44:42 INFO – jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for application/xhtml+xml is
    2011/11/29 14:44:42 INFO – jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for application/xml is
    2011/11/29 14:44:42 INFO – jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for text/xml is
    2011/11/29 14:44:42 INFO – jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for text/vnd.wap.wml is org.apache.jmeter.protocol.http.parser.RegexpHTMLParser
    2011/11/29 14:44:42 INFO – jmeter.gui.util.MenuFactory: Skipping org.apache.jmeter.protocol.http.modifier.gui.ParamModifierGui
    2011/11/29 14:44:42 INFO – jmeter.gui.util.MenuFactory: Skipping org.apache.jmeter.protocol.http.modifier.gui.UserParameterModifierGui
    2011/11/29 14:44:42 INFO – jmeter.protocol.http.sampler.HTTPSampler: Maximum connection retries = 10
    2011/11/29 14:44:42 WARN – jmeter.gui.util.MenuFactory: Missing jar? Could not create org.apache.jmeter.visualizers.MailerVisualizer. java.lang.NoClassDefFoundError: javax/mail/MessagingException
    2011/11/29 14:44:42 INFO – jmeter.samplers.SampleResult: Note: Sample TimeStamps are START times
    2011/11/29 14:44:42 INFO – jmeter.samplers.SampleResult: sampleresult.default.encoding is set to ISO-8859-1
    2011/11/29 14:44:47 INFO – jmeter.engine.ClientJMeterEngine: about to run remote test
    2011/11/29 14:44:47 INFO – jmeter.engine.ClientJMeterEngine: done initiating run command
    2011/11/29 14:44:47 INFO – jmeter.engine.ClientJMeterEngine: running clientengine run method
    2011/11/29 14:44:47 INFO – jmeter.engine.ClientJMeterEngine: sent host =192.168.0.62
    2011/11/29 14:44:47 INFO – jmeter.engine.ClientJMeterEngine: sent test
    2011/11/29 14:44:47 INFO – jmeter.engine.ClientJMeterEngine: sent run command
    2011/11/29 14:44:47 INFO – jmeter.gui.util.JMeterMenuBar: setRunning(true,192.168.0.62)
    2011/11/29 14:53:23 INFO – jmeter.engine.StandardJMeterEngine: Listeners will be started after enabling running version
    2011/11/29 14:53:23 INFO – jmeter.engine.StandardJMeterEngine: To revert to the earlier behaviour, define jmeterengine.startlistenerslater=false
    2011/11/29 14:53:23 INFO – jmeter.engine.StandardJMeterEngine: Running the test!
    2011/11/29 14:53:23 INFO – jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*)
    2011/11/29 14:53:23 INFO – jmeter.engine.StandardJMeterEngine: Starting 1 threads for group Thread Group. Ramp up = 1.
    2011/11/29 14:53:23 INFO – jmeter.engine.StandardJMeterEngine: Continue on error
    2011/11/29 14:53:23 INFO – jmeter.threads.JMeterThread: jmeterthread.startearlier=false (see jmeter.properties)
    2011/11/29 14:53:23 INFO – jmeter.threads.JMeterThread: Running PostProcessors in forward order
    2011/11/29 14:53:23 INFO – jmeter.threads.JMeterThread: Thread Thread Group 1-1 started
    2011/11/29 14:53:54 INFO – jmeter.threads.JMeterThread: Thread Thread Group 1-1 is done
    2011/11/29 14:53:54 INFO – jmeter.engine.StandardJMeterEngine: Ending thread Thread Group 1-1
    2011/11/29 14:53:54 INFO – jmeter.engine.StandardJMeterEngine: Stopping test
    2011/11/29 14:53:54 INFO – jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test
    2011/11/29 14:53:54 INFO – jmeter.services.FileServer: Default base=C:\Documents and Settings\ds111256\Desktop\jmeter-2.3.2\bin
    2011/11/29 14:53:54 INFO – jmeter.gui.util.JMeterMenuBar: setRunning(false,*local*)
    2011/11/29 14:53:54 INFO – jmeter.engine.StandardJMeterEngine: Test has ended

  2. I have been looking for a practical guide to TCP sampler, its rarely used and hence not covered much. Thanks for putting this post, You saved me a ton of time. I had to use TCP as i had to send 100-1000 parameters in the request and using HTTP Sampler would have killed my time.

    thanks again

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: