Open a Socket Connection

I have an RFID reader that has an internal memory bank that
stores rfid scans. From speaking to the company in order to get the
data off I need to create a socket connection to port 8080 and send
RQL (which is similar to sql) and then it will send me back piped
results.
Can anyone assist me on how to open a connection to ip
192.168.1.139 port 8080 and send this
SELECT read_count, protocol_id, antenna_id, id FROM tag_id
WHERE protocol_id='GEN2' set time_out=8000
and then output the results it returns.
Thanks in advance!

Thanks for your response, ok i've change the code to use the
following, but now it just hangs... i.e. it looks like it's working
in the browser but then just times out.
<cfsetting requesttimeout="1000">
<cfflush interval="5">
<!-- begin code sample -->
<cfset serverStruct = structNew() />
<!-- the variables -->
<cfset serverStruct.serverIp = "192.168.1.139" />
<cfset serverStruct.serverPort = "8080" />
<cfset serverStruct.portConnected = "" />
<cfset sLines = "">
<!--- Create the socket object --->
<cfset objSocket = CreateObject("java", "java.net.Socket")
/>
<!--- Connect --->
<cftry>
<!--- Set up socket to IP:port of remote server --->
<cfset objSocket.init(serverStruct.serverIp,
serverStruct.serverPort)/>
<cfset serverStruct.portConnected =
objSocket.isConnected()>
<!--- Did we connect? --->
<cfif serverStruct.portConnected>
<!-- create the string. Note the use of quotes to escape
quotes in a string -->
<cfset mySendData = "SELECT id FROM tag_id WHERE
protocol_id='GEN2';">
<!--- obtain the streams --->
<cfset input = objSocket.getInputStream()>
<cfset output = objSocket.getOutputStream()>
<!--- set up buffered reader for the socket; it will read
character data
into a buffer until until enough of it can be processed
efficiently. However,
a buffered reader reads a reader object, hence we first have
to convert the
inputstream into a reader --->
<cfobject class="java.io.BufferedReader" name="brObj"
action="CREATE" type="JAVA">
<cfobject class="java.io.InputStreamReader" name="isrObj"
action="CREATE" type="JAVA">
<cfset streamReader = isrObj.init(input)>
<cfset dataBuffer = brObj.init(streamReader)>
<!--- send the data to the remote server --->
<cfobject class="java.io.PrintStream" name="pwObj"
action="CREATE" type="JAVA">
<cfset writer = pwObj.init(output)>
<cfset sentData = writer.println(mySendData)>
<!--- Get the response from the server --->
<!---<cfset response = dataBuffer.readLine()>
<cfset sLines = "">--->
<cfset sLine = dataBuffer.readLine()>
<cfloop condition="#isDefined('sLine')#">
<cfset sLines = "#sLines##sLine#">
<cfset sLine = dataBuffer.readLine()>
</cfloop>
<!--- Close the streams and the connection --->
<cfset streamReader.close()>
<cfset dataBuffer.close()>
<cfset writer.close()>
<cfset objSocket.close()>
</cfif>
<cfcatch type="any">
something went wrong.
</cfcatch>
</cftry>
<cfdump var="#sLine#">

Similar Messages

  • Failed to open a socket connection to the Authentication Manager

    Hello,
    When I use utcapture command, I get the error *�Failed to open a socket connection to the Authentication Manager�*.
    SO: Solaris 10 8/07
    SRSS: Sun Ray Server Software 4.0
    LAN Configuration
    Thanks.

    Since the question was also posted to the sunray-users alias, see http://www.filibeto.org/pipermail/sunray-users/2007-December/008281.html for the answer. (Which currently seems to be that the Sun Ray auth daemon was not running.)

  • Having problems with shut-down of server after I open a socket connection (which fails to connect)

    Basically here is an example servlet - new iPlanet 4.1sp9 instance with an empty classpath (apart from the servlet class) - running solaris v5.6 (Generic_111446-02)
    If you run the servlet and then try to shut-down iPlanet it hangs. If you remove the 'new Socket(...' line then it's fine. Any ideas why a failed socket connection stops the server restarting? (Connecting to a listening port does not exhibit this behavior).
    Cheers, source follows:
    * SocketServletTest.java
    * Created on 02 April 2002, 09:30
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.net.Socket;
    * @author kingrb
    * @version
    public class SocketServletTest extends HttpServlet
    private static boolean startedThread = false;
    /** Initializes the servlet.
    public void init(ServletConfig config) throws ServletException
    super.init(config);
    /** Destroys the servlet.
    public void destroy()
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException
    response.setContentType("text/html");
    java.io.PrintWriter out = response.getWriter();
    if (!startedThread)
    out.println("Starting thread");
    Thread t = new SocketThread();
    t.start();
    startedThread = true;
    out.println("Started thread);
    out.println("test");
    out.println("Prop is: " + System.getProperty("MyProp"));
    out.close();
    /** Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException
    processRequest(request, response);
    /** Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException
    processRequest(request, response);
    /** Returns a short description of the servlet.
    public String getServletInfo()
    return "Short description";
    private class SocketThread extends Thread
    public void run()
    int counter = 0;
    String errMsg = null;
    while (1==1)
    counter++;
    Socket s = null;
    try
    s = new Socket("127.0.0.1", 27087);
    s.close();
    catch(Exception e)
    errMsg = e.getMessage();
    if (s != null)
    errMsg += " & NOT NULL";
    try
    {s.close();} catch(Exception e2)
    System.setProperty("MyProp", String.valueOf(counter) + " - " + errMsg + "<BR>" + System.getProperty("java.class.path"));
    try {Thread.sleep(30000);} catch(Exception e) {}
    }

    Rob:
    it's due to JVM signal handler that catches the stop signal and you're forced to use a kill -9 -
    Note that the stop script of a fresh install of iWS 4.1SP9 should contain the kill -9 - as a workaround for this known JVM issue.

  • Can my application open a socket connection?

    Hi,
    We're evaluating Azure as a PaaS, and wanted to please ask - are there limitations on opening outgoing connections (TCP sockets) from the hosted application, to an some external legacy machine (outside of Azure).
    For example, a JDBC driver that connects to our ancient legacy database (we understand it offers much less than Azure SQL, but it's used for very limited non-critical data).
    Thanks very much 

    Hi,
    Based on my understanding, what you mean may be connecting on-premises servers to Windows Azure roles with Windows Azure Connect. I found an article, hope this helps.
    http://blogs.technet.com/b/uktechnet/archive/2011/07/27/how-to-connecting-on-premises-servers-to-windows-azure-roles-with-windows-azure-connect.aspx
    Best Regards
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to know if a socket connection is open ?

    Hi,
    I have a ftp class that opens a socket connection to a ftp server. Sometimes the connection is closed and I get an exception. There is any way to know if exists an open connection ?
    Thanks !

    From SDK v1.3.1 for abstract Class SocketImpl:
    Method connect
    protected abstract void connect(InetAddress address,
                                    int port)
                             throws IOException
        Connects this socket to the specified port number on the specified host.
    Parameters:
    address - the IP address of the remote host.port - the port number.Throws:
    IOException - if an I/O error occurs when attempting a connection.... So if it throws an exception on inception, it's NOT connected - NOT open, right? This is the class you've subclassed to create the socket connection? If not, which?

  • Problem with socket connection

    have my gps reciver connected to the usb port - i have a daemon gpsd running which makes data available on tcp port 2947 for querying. when i do telnet, it gives proper data.
    but when i open a socket connection using java, it does not print anything as output. actually telnet asks for an escape charatcer so i am sending "r" initially to the server but still the program does not print anything as output.
    here is my java code -
    import java.io.*;
    import java.net.Socket;
    public class test2
    public static void main(String[] args)
    try
    Socket s = new Socket("localhost",2947);
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
    s.getOutputStream())),true);
    out.println("r");
    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    String line;
    while(true)
    line = in.readLine();
    System.out.println(line);
    catch (Exception e)
    or sometimes it even shows error as
    Exception in thread "main" java.net.SocketException: Invalid argument or cannot assign requested address
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    and this is the output which i get on telnet -
    ot@localhost ~]# telnet localhost 2947
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    r
    GPSD,R=1
    $GPRMC,000212,V,18000.0000,N,00000.0000,W,0.0000,180.000,101102,,*1A
    $GPGSA,A,1,,,,,,,,,,,,,,,,*32
    $PGRME,400.00,0.00,0.00*7B
    $GPRMC,000213,V,18000.0000,N,00000.0000,W,0.0000,180.000,101102,,*1B
    $GPGSA,A,1,,,,,,,,,,,,,,,,*32
    $PGRME,400.00,0.00,0.00*7B
    $GPRMC,000214,V,18000.0000,N,00000.0000,W,0.0000,180.000,101102,,*1C
    $GPGSA,A,1,,,,,,,,,,,,,,,,*32

    Actually the problem does not seem to be in the code because i tried some basic client server programs (without any gpsd etc in picture) and even they are not working in linux though they work perfectly in windows (on the same machine). In linux it shows exception
    My socket programs dont work in linux it shows error -
    ot@localhost winc]# java parser
    Exception in thread "main" java.net.SocketException: Invalid argument or cannot assign requested address
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
    at java.net.Socket.connect(Socket.java:452)
    at java.net.Socket.connect(Socket.java:402)
    at java.net.Socket.<init>(Socket.java:309)
    at java.net.Socket.<init>(Socket.java:124)
    at parser.main(parser.java:10)
    i have removed the firewall settings etc and it still doesnot work in linux
    what could be the cause for this?
    Sowmya

  • How to retain socket connection for multiple requests in java 1.3

    Hi All,
    My problem is to retain client socket connection without opening and closing socket connection for every request.I want to open the socket connection once and send multiple requests one after the other based upon the response over the same socket.Finally I want to close the socket only after completing all my requests and receiving respective responses.I don't want to open and close the socket for each request and response.While at the same time I expect the socket to send each request only after receiving the response for the previous request.
    I am using java 1.3 and I am looking for the solution in same version.
    Please help me .
    Thanx in advance.

    Look at my response to "Telnet to Unix box from Java"
    http://forum.java.sun.com/thread.jsp?forum=31&thread=437231
    on "Java Programming" forum. It does exactly that to run the signon and a command. It would be easy to extend it to do multiple commands.

  • Multiple socket connections with MIDP

    dear experts,
    I have a simple problem and I hope someone can help me to solve it.
    I need to open a socket connection from multiple MIDlets on the same port.
    This error occours when I try to make a socket push registration from the second (or third, or fourth...) midlet (I'm able to connect to the socket correctly from the first midlet that makes a push registration):
    PushProcessor.run Exceptionjava.io.IOException: ServerSocket Open
    java.io.IOException: ServerSocket Open
         at com.sun.midp.io.j2me.serversocket.Socket.open(+39)
         at com.sun.midp.io.j2me.socket.Protocol.openPrim(+127)
         at javax.microedition.io.Connector.openPrim(+121)
         at javax.microedition.io.Connector.open(+15)
         at javax.microedition.io.Connector.open(+6)
         at javax.microedition.io.Connector.open(+5)
         at it.myprj.midp.BasicPushMIDlet$PushProcessor.run(+16)
    I would know if push registry API allows to have multiple connection on the same socket port.
    any help is appreciated!
    giovanni

    in my opinion,
    due to the fact when an app binds one port and a second app tries to bind the same (@same time) there will ever be a exception (from my point of view)!
    an no i think that push registry cant register two apps on same port (eg datagram://5060)
    hope this helps
    chris

  • Lost data on socket connection!

    Hi all,
    I have opened a socket connection with another pc, I pass it some parameters and in case of error it send back to me a big number of informations. The problem is: some informations are lost, in particular the first that is "code error", are there some ways to catch all informations with nothing loss?
    Thanks!!!

    Yes, it is possible to use sockets without losing information. In fact, getting all information trough with no loss is the normal behavior of sockets, and the behavior you get must be because of errors in your code.

  • Studio Creator, Socket Connection to External Device

    I am porting an existing & successful project from Netbeans 3.6 into Studio Creator to take advantage of some of the tools in the IDE for this application. The project requires opening a socket connection from the Server PC to an external Device (PLC) that is a Client on a static IP & a dedicated fixed port.
    I am struggling to get past some security settings specific to AccessControlExceptions. Here is the code method being used to test:
    public String button1_action() {
    // Call methods to open connection, init streams, send command, and close connection.
    try {
    // Open Socket up and accept client connection
    ipSocketObject = new ServerSocket(port);
    bfSocket = ipSocketObject.accept();
    // Establish Streams
    is = new BufferedReader(new InputStreamReader(bfSocket.getInputStream()));
    os = new PrintWriter(bfSocket.getOutputStream(), true);
    System.out.println("Got to here...");
    // Clear the msCounter #13002
    os.println("r13002=0");
    pattern = "13002";
    do{ret=is.readLine();} while ((ret.indexOf(pattern)) ==-1);
    is.close();
    os.close();
    bfSocket.close();
    ipSocketObject.close();
    } catch (IOException e) {
    e.printStackTrace();
    return null;
    The Socket Connection is established, but the command string is not processed before Studio Creator generates a AccessControlException Fault. I have experiemented putting in a SocketPermission statement with out success.
    Is anyone aware of some sample code I might be able to review for opening socket connections to clients in a Studio Creator Application? Please excuse this request if too rudimentary- I am an Industrial Controls guy by trade... :)

    Sorry I know of no such application at this time, and unfortunately have not done socket work myself for many moons....
    What JDK was your previous application written under? I googled for AccessControlException and socket and seems that sometimes accounts for some issues... you can also search for that combination in the forum advanced search and might find something there.... one more long shot suggestion based upon your statement "the command string is not processed".... could it be that you need to flush the stream...?
    Sorry I don't have more to offer...
    v

  • Too many open socket connections causing ColdFusion to crash?

    I’m currently working on an e-commerce site which sends and receives information to/from the client’s order management system via XML over a TCP/IP socket.  It uses a very old java-based custom tag called CFX_JSOCKET (which appears to have been written in 2002) to open the socket, send the data, and get the response.  The code that calls the custom tag and sends/receives data from the OMS pre-dates my working on the site, but its always worked, so I haven’t paid it much attention.
    Back in the summer of 2009 we started experiencing issues with ColdFusion (v.7 on Window 2003 at the time) locking up on a more and more frequent basis, until it ultimately became a daily issue.  After extensive research we narrowed the issue down to the communication between the web server and our client’s order management server.  It seemed the issue with ColdFusion hanging was either related to there being too many connections open, or to these connections hanging and resulting in dead threads.  This an educated guess based on a blog post I’d seen online, not actual monitoring of either CF or the TCP/IP connections.  As soon as we dialed back the timeout on the CFX_JSOCKET tag from 20 seconds to 10, the issue disappeared, so we left it at that and moved on.
    Fast forward to this January. The site is hosted at a new location, on a 64-bit Windows 2008 box running ColdFusion 9.  Over the years traffic on the site has continued to grow.  The nature of the clients business means that August and January are their business times of the year (back to school for college kids) and in January ColdFusion once again started locking up on an almost-daily basis.  
    One significant difference is that the address cleansing software that previously ran on the box and was used to verify shipping addresses is not available for 64-bit, so when we moved to the new server last summer, that task was moved to the client’s order management software and handled via XML like all other interaction with that system. However, while most XML calls to that server (order input, inventory check, etc) take under a second to complete, the address cleansing call regularly takes over 5 seconds to return data, and frequently times out. 
    Once we eliminated the address cleansing call from the checkout process, ColdFusion once again stopped locking up regularly.  So it appears that once again it’s the communication between the web server and the order management server that’s causing problems. We currently have that address cleansing call disabled on the web site in order to keep ColdFusion from crashing, but that’s not a long term solution.
    We don’t have, nor can I find online, the source code for the CFX_JSOCKET custom tag, so I decided I’d write some CF code utilizing the java methods to open the socket, send the data, get the response, and close the connection.  My test code is working fine (under no load).  However, in trying to troubleshoot an issue I had with it, I started monitoring the TCP/IP connections using TCPView.  And I noticed that all the connections to the order management server, whether opened via the custom tag or my new code, remain open in either a TIME_WAIT or FIN_WAIT2 status for well over 2 minutes, even though I know for a fact that my new code is definitely closing the connection from the web server side. 
    They do all close eventually, but I’m wondering 1. Why they’re remaining open that long; 2. Is that normal; and 3. If all these connections remaining open could be what’s causing ColdFusion to choke. 
    Does this sound plausible?  If so, does anyone have any suggestions/recommendations about how to fix it?  My research seems to indicate this might be a matter of the order management system not closing the connection on its end, but I’m in way over my head, and before I go to client and tell them it’s their OMS causing the issue, I need to feel a little more confident that I’m on the right track. 
    Any help or advice would be very greatly appreciated.  And thanks for taking the time to read through my long-winded explanation of the problem.
    Set-up details:
    ColdFusion Version: 9,0,0,251028  Standard 
    Operating System: Windows Server 2008 
    Java Version: 1.6.0_14 
    Java VM Name: Java HotSpot(TM) 64-Bit Server VM 
    Java VM Version: 14.0-b16 
    Thanks,
    Laurie

    Hi Laurie,
    Not aware of custom tag called CFX_JSOCKET. I guess the process you described very well is consuming a resource then you are getting a problem. Trick is what parameter to adjust. Perhaps you are running out of one the threads in CFadmin > Server Settings > Request Tuning.
    I expect if you enable CF Metrics logging where you can log the threads and other resources then you can find out which parameter needs adjusting. Let me know if you want some details on enabling CF Metrics. Perhaps others will have much better idea than me and help without the overhead of logging.
    The other interesting thing is you are using CF9.0.0. Do you have some reasons for not being on updater1 CF9.0.1?
    HTH, Carl.
    PS I posted before however seems to have gone, just hope does not come back and then I have posted twice.

  • Cannot open socket connection on port 443

    Hi!
    Our server is running on Port 443.
    When I try to Connect from the BlackBerry 9300, an exception is thrown "cannot open socket connection on port 443"
    Can any one please help me in finding the solution to enable the port 443.
    Thank you in advance!
    Regards,
    Vinay

    I assume that you have verified that you can login to the ftp site using a regular ftp client (e.g. Fetch) on the Mac?

  • Keep opened socket connection?

    Hi,
    My Java application communicates with server on average every 3 seconds. I wonder if it is a good idea to keep an opened socket connection to the server and don't open new connection for each request. The problem with this is that if in the meantime is connection aborted, java.net.SocketException is throwned.
    What do you think about keeping opened connection? Is appropriate to work with opened connections or to open new connection for each new request? How do you solve in your applications situation when communication is irregular but frequent.
    Thanks.

    I had one more question on this topic relating to capture and processing exceptions. Communication between client and server I accomplish wit these three classes:
    - ClientRequest - represents client request to the server
    - Communication - gets ClientRequest and socket connection to the server and sends the request to the server
    - ServerResponse - represents response returned from the server
    Now If Communication class gets dead connection it can't work and throws an exception. We discussed that I should find out the situation and suitably respond to this situation.
    My question is whether the method for reconnection should call:
    a) Communication class
    b) class that uses the Communication class?
    c) somebody else (?)
    In case a) there is an advantage that all is in one place and Communication class user does not have to worry about anything beause class will try reconnect itself (if second attempt fails, method throws another exception). The advantage of b) is that the user needs, he can respond to this situation and do some another action.
    Thanks.

  • Is it wise to keep the socket connection open?

    When u have a bunch of HTTP requests coming in to a listener server socket, would it be safe to keep my JAVA socket connection open with KeepAlive or simply open/close at will? I thought of a connection of sockets as well. Thoughts? thx!

    It depends which socket your talking about
    The serversocket you want to always be open and listened to
    the sockets it spawns you should close when you've finished the transaction

  • Open a socket from a LAN (with a proxy connect to internet) to outside

    Hi everybody
    I have a chat program that opens a socket through which I sent voice data. Every one that wants to receive voice must open a sockect to the computer sending the voice. (It means that if you want to send data you must open a socket to another computer and if you want to receive you S.O. must open a socket to you). It works ok with all computers inside the LAN. Now I'd like to stablish a connection to a computer which is outside this LAN (my computer at home). From here, using some ports which are not closed by the firewall at the proxy I can connect my computer at home.
    My questions are:
    Can I use the same socket to send and receive data? Or they are only 'one-way' direction, so I need another socket from home to here?
    How can I open the socket from home to here? Is there a way to send my computer at home the whole addres at work? I mean sent my computer at home my 'mac address' or something so the proxy knows where to send the packages received from outside?
    Thanks,
    Dani.
    I WILL GIVE YOU 10 DUKES IF YOUR SOLUTION WORKS.

    How can I open the socket from home to here? Isthere
    a way to send my computer at home the whole addresat
    work? I mean sent my computer at home my 'mac
    address' or something so the proxy knows where to
    send the packages received from outside?This can't be done (as far as I know).
    /KajOr, well. You might be able to configure the proxy to do port forwarding, but I guess that you don't want to do that?

Maybe you are looking for

  • Doubt s in ABAP HR -Enhancements

    Hi Experts,         I am working in enhancements, I have  some doughtes in that ,so plz do help to me, ””””My enhancement is, Whenever we enter data such as Emp Firstname, emp.lastname,empdate of birth, in ‘pb10’  this data should check in PAP databa

  • Adobe Flash CS6 Crashes

    Hi, I have Adobe Flash CS6 on my mac which I have been able to use fine up until recently. It all seems to load okay but then no toolbars or anything appear and when you try to open or create a new document it crashes out. The attached image is of th

  • Acrobat 7 standard

    I use acrobat 7 standard, show this"The application is being terminated because of memory corruption" & and can't update . how to do that?

  • Is there any query i can use to monitor Users tried to log on to data base

    is there any way to know the users tried to log on to data base is this possible if user entered user name and wrong password 4 times for example is there a table or something let me know that for example HR tried 4 times to log into data base

  • Installing Business content in SRM

    Hi, I am trying to bring data from SRM to BW basically for contract management and vendor evaluation.Someone has already done Transfer Component Hierarchy.But this is all under <b>nodesnotconnected</b>.And most of them dont have text.What can I do to