Multiple Socket Connections

Hi,
i need to simulate a http-POST by using a StreamConnection.
This has to happen a lot of times, one post after the other.
Server is closing the socket after each POST, so that i have to call a Connector.open(...) before each POST.
The Problem now is, that the 3rd ED devices i use are showing the IAP-Dialog, asking for a new Connection to a IAP, although the old internet connection is still open.
Is there any way to prevent this problem and make the client ask for Access Point connection only with the first Connector.open(..) call?
Best Regards,
Andi

The domein is not changing, i wrote a small testcode to simulatre this problem.
here you are:
private StreamConnection streamConnection = null;
private String connectString = "socket://www.someaddress.com:80";
for( int i = 0; i<5; i++ )
try
streamConnection = (StreamConnection)Connector.open(connectString);
catch( Exception e){}
finally
try{
if(streamConnection != null)
streamConnection.close();
}catch(Exception ignore){}
}This code is showing the question for internet access point five times.
Problem is that we need the close of the socket, because of the servers architecture.
Best Regards
Andi

Similar Messages

  • 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

  • Multiple socket connection in TC65

    Hello!
    I connect TC65 with server by socket connection on port 23. I close this socket, output and input streams as well. Because I've read some information from server I want to connect to another device using socket connection on port 43 for example, but it seems it doesn't work. I guess in some way it could be done because I closed previous connection. Any advise?
    Luke

    ok. dear
    my another id is      [email protected]
    Right, I'm getting tired of this already.
    NO, I'm not going to send you any code, you lazy nitwit. Neither will anybody here.
    Your use of the imperative form in your question is rude. You may talk like that to your colleagues, but in a forum where people answer questions in their spare time and on a voluntary basis this is inacceptable.
    You didn't even bother to say "please", at the least. Not that this would have changed much, but at least you wouldn't have been barking.
    [url http://www.catb.org/~esr/faqs/smart-questions.html]This document might provide you some orientation.
    As for your problem, first find out what exactly it is you want to do. Search the web, as kajbj counselled, it's quite a common task. If you have a specific problem, ask. But, take my advice and never, never ever ask people to "send you code" in a forum.

  • Multiple sockets connected to one port

    Hello I am running a LabVIEW VI that is based on the Labview TCPServer example. I am wondering what the best way to deal with multiple connections to a single port would be. For example I have a device(could be thought of as the same thing as the TCPClient vi) that connects to the server using the port number and the IP address. The communication works fine when there is only one device trying to connect to the server, the problem occurs when two devices try to connect to the server. When the first device connects all data sent shows up fine, when the second device connects, the status on the device indicates a proper connection but none of the data sent shows up on the server side. I assume that I must do something with the connection ID to distinguish between the two connections, but I was wondering if there was an example or something that deals with this issue, or if someone would like to explain how I could get the data to show up properly. Any help is appreciated, thanks!

    I am hoping that there is something similar to the java api where there is some way I can start a new threads to handle multiple connections on the same port. I would assume that if java has it LabVIEW would have something similar. Unfortunately I am not sure how to go about finding out how to do such a thing in LabVIEW.
    The way that I assume the TCPListen.vi works is that there is some mechanism polling the specified port and ip address waiting for a request for a connection. Once a request is received the VI creates a connection ID so that the other subvi's can perform operations on the specific connection. It also looks as though the TCPListen.vi continues to listen for new connections, because the clients indicate a connection when more then one of them are run trying to connect to the same port and IP.
    So my question is either, how to start a parallel process to handle the new connections, or where can I find the new connection ID (because the indicator only shows the connection id of the first client to connect). Basically I am having trouble distinguishing between the multiple connections on the same port.I would like to keep all of the clients sending data through the same port if possible.Each client identifies itself in its data message so keeping the data organized is not a problem. 
    I also looked at the data socket examples, mainly because the Java examples I was looking at used "Sockets". I ran into similar troubles finding a way to create distinguishable connections using DS's as well. Anyways, any help is appreciated. Thanks.

  • Multiple input stream in one socket connection

    Can we have multiple input streams for a java socket connection? It means that in a client/server application (creates using java socket), can we have multiple input streams for the client side program. For example, the input streams are to cater for the need of letting the user to chat and downloading some files from the chat partner at the same time. And do we need to use thread to create the multiple input streams like the case when we create a multithreaded server? Anyone out there who knows the solution please post it. Thanks in advance.

    Can we have multiple input streams for a java socket
    connection? It means that in a client/server
    application (creates using java socket), can we have
    multiple input streams for the client side program.
    For example, the input streams are to cater for the
    need of letting the user to chat and downloading some
    files from the chat partner at the same time. And do
    we need to use thread to create the multiple input
    streams like the case when we create a multithreaded
    server? Anyone out there who knows the solution please
    post it. Thanks in advance.Ok im no expert here but this is what i learned:
    a Socket can have only one InputStream (Socket.getInputStream()) and one OutputStream Socket.getOutputStream()). So you will have to create a way to make multiple Socket connections in your client program. And yes, you have to use threads for your server. if you dont the client will have to wait until the user before them is finished with the connection before being able to connect. I hope this helps you out. BTW please check out http://www.javabible.com. they have the book online now for free.
    Joeyford1

  • How can i reuse my existing socket connection

    Hi,
    this might sound basic, it probably is:
    As part of my larger project, i have to send and recieve data to multiple socket connections.
    The thing that happens is that everytime i send data, it seems that java is creating a new stream or something (code is multithreaded)
    so as i send 4 items of data, a bit like a chat program sending 4 statements, it creates 4 different streams, instead of using the same stream. therefore when i close the connection, i get:
    java.net.SocketException: Connection reset 4 times.
    i know why.. its because i have added the:
    Socket socket=new Socket(host, port);
    BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
    bit in the same method with the
    out.println(THE DATA....);
    out.flush();
    The thing what i want to do is to create the connection one, and reuse the objects:
    out, in and socket
    to send / recieve the new data.
    please help me guys,
    thanks

    All the threads would be able to get the same reference to....
    class SocketWrapper {
         private final Object readLock = new Object();
         private final Object writeLock = new Object();
         // client side
        public SocketWrapper(String hostname, int port);
         // server side.
        public SocketWrapper(Socket);
         // send data
         public void send(Serializable object) throws IOException;
         // receive data. synchronized(writeLock);
         public Serializable getNext() throws IOException;
         // create a new socket as required, throw IllegalState if server side. synchronized(readLock)
         private void createNewSocket() throws IllegalStateException;
    }The send autoconnects as required. It then send on message/packet/object.
    The getNext autoconnects as required. It reads one message/packet/object and returns.
    This allows multiple threads to access the same socket. It allows data to be sent while a thread is blocking on a read. (Thus two locks)

  • Multiple clients on socket connection

    Hi!
    I understand that it is possible that multiple clients listen to one server (on the same port) and even write to it (then it should be a multi-threaded server).
    But i would like to refuse connectios, if one client is connected. How can I do that?
    In my case I have a (single threaded) server. Now one clients connects. The server waits to receive data from the client and answers, without ever closing the port. that works.
    Now if I connect with a second client, the openicng of the socket in the second client works fine, although the server does not seem to notice the second client. Communication is not possible between the server and the second client, and the server doesn't answer to the first client anymore, although he receives data from it.
    So, since the server does not seem to notice the second client (does not accept the connection) and I don't get an exception at the second client, what can I do?
    Thank you for your help!
    concerned Code (if you want to take a look at it):
    CLIENT:
    socket = new Socket(hostname, echo_port);
    SERVER:
    try
    ServerSocket waitingsocket = new ServerSocket(echo_port);
    try
         socket= waitingsocket.accept();
         System.out.println("Client connected");
         ReaderThread reader = new ReaderThread( this, socket );
         reader.start();          
    catch (Exception e)
    READER:
    public void run()
         while (true)
              try {
                   int bytesRead = inStream.read(inputBuffer,
                   0, inputBuffer.length);
                   readCallback.tcpUpdate(inputBuffer,bytesRead);
              catch (Exception oops)
                   readCallback.tcpUpdate(null,-1);
              

    Just to make sure this is clear: You can NOT have multiple clients on a given socket connection. You CAN have multiple clients connected to a particular port on a given server, but each client will be communicating with the server through a different of socket.
    The usual approach here is to set up a listening ServerSocket on the desired port, call accept() on it, then process the communication from the returned Socket object. This is usually done by spawning a new thread and allowing it to handle the socket communication, while the ServerSocket loops around to another accept() for the next communication.
    Here's an excellent intro to the concepts (the code is really ugly and poorly implemented, but it does a good job of explaining the overall concept). I used this as a starting point, and now (after a whole lot of development) have a pretty sweet extensible web server class that handles template expansion, etc... (I use this as a quick and dirty UI for some of my apps, instead of requiring the user to install a JSP container):
    http://developer.java.sun.com/developer/technicalArticles/Networking/Webserver/
    - K

  • 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.

  • Tomcat multiple JPDA socket connections

    I'm running Tomcat 5.5 in a Linux server, and remote debugging with NetBeans, via JPDA dt_socket transport.
    The server denies multiple debuggers connection. After the first remote debugger attachs, the server stop listening the port.
    Is it possible, having multiple debuggings at the same server, at same time?

    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

  • Maximum number of socket connections?

    Hi there,
    I've done a test to check what is the maximum simultanenous socket clients can connect to a socketserver.
    The code is as follows:
    --------- The Server ------------
    import java.net.*;
    public class Server {
         public void start() {
              int counter = 0;
              try {
                   ServerSocket server = new ServerSocket(9999);
                   System.out.println("Server started.");
                   while (true) {
                        Socket connection = server.accept();
                        counter++;
                        System.out.println("Client " + counter + " connected.");
         catch (Exception ex) {
         public static void main(String args[]) {
              Server obj = new Server();
              obj.start();
    ----------- The Client -----------
    import java.net.*;
    public class Client {
         public static final int NUMBER_OF_CLIENTS = 20; // number of simultaneous connections.
         class ClientThread implements Runnable {
              Thread t;
              int id;
              public ClientThread(int id) {
                   t = new Thread(this);
                   this.id = id;
                   t.start();
              public void run() {
                   try {
                        Socket connection = new Socket(InetAddress.getLocalHost(), 9999);
                        System.out.println("Client " + id + " connection OK!");
                        //connection.close();
              catch (Exception ex) {
                   System.out.println("Client " + id + " connection Failed!");
         public void start() {
              for (int i = 0; i < NUMBER_OF_CLIENTS; i++)     {
                   ClientThread t = new ClientThread(i+1);
         public static void main(String args[]) {
              Client c = new Client();
              c.start();
    Test env: Windows XP Sp1
    Test results: There is atleast one client which has connection refused.
    Questions:
    1) Is the situation platform-dependent?
    2) Is it possible to configure connection limit on server socket?
    Thanks for paying attention.
    Trung

    Oh, it doesn't work!
    Client 1 connection OK!
    Client 20 connection OK!
    Client 19 connection OK!
    Client 18 connection OK!
    Client 17 connection OK!
    Client 16 connection OK!
    Client 11 connection OK!
    Client 10 connection OK!
    Client 15 connection OK!
    Client 14 connection OK!
    Client 13 connection OK!
    Client 9 connection OK!
    Client 8 connection OK!
    Client 3 connection OK!
    Client 4 connection OK!
    Client 5 connection OK!
    Client 6 connection Failed!
    Client 7 connection Failed!
    Client 2 connection OK!
    Client 12 connection OK!
    I've executed 5 times, the 5th one has showed the
    error.I doubt this has anything to do with a 'limit' in the OS.
    A box can only process so much at once. That includes establishing connections.
    High volume situations are handled by using multiple servers and a front end load balancing router.

  • Monitering Multiple Sockets in one thread

    Hi all
    i have a problem.....i want to create and moniter multiple sockets BUT Due to resourse problems i cannot create as many threads. I want to use multiple sockets in one thread.
    Cani do something where i can have array of sockets and poll for data in a single while loop for all the sockets...OR u may suggest another solution for my porblem of using multiple sockets in one thread.
    thanks in advance
    Sai Burra

    Here's a pseudocode solution I've used:
    Create a thread to listen to incoming connections. Upon incoming connection, add the socket and inputstream to the incoming messages listener thread.
    Create a threadpool for outgoing messages.
    Create a thread to process incoming messages.
    Incoming message listener thread:
    Create a hashtable of sockets. Socket is the key, inputstream is the value.
    Loop through each key, and assuming BufferedReader input you can poll by using (input.isReady()). If isReady() returns true, that means there is data on the stream coming in, so you'll need to process it.
    After processing the data, call a thread from your outgoing messages threadpool to send the response - in case there is blocking, you'll still be able to process the rest of your data.
    Sleep the incoming messages thread for 200 ms (300-400ms is quite adequate for real time processing I've found, at least the slowdown isn't noticable).
    This should work for what you're talking about.

  • Multiple Sockets on Palm

    Hi, I'm working on a Palm application in a Palm Emulator connected to a SocketServer. I'm accessing SQL Server DB to retrieve items to put on my combobox. Now that I retrieved the items, I need to send them to the Palm application. Previously, I concat the items into one string, send them to the Output Stream using the write() method. Then I realised that J2ME CLDC does not support StringTokenizer which I used to process any string from the palm to the server.
    So now I've stored the combobox items into a Vector and I want to send the elements one at a time through many sockets. So my question is how does a Server send multiple sockets?
    Please keep in mind that I am using J2ME CLDC and all J2ME socket examples I've seen only shows one socket and only one file being sent and received.
    Please reply, thanks.
    zad.

    I think you should try making your own stringtokenizer instead.

  • SAP PCO Socket Connection VS HyperTerminal

    Hi All,
    We're trying to process an IP Barcode Scanner message using PCo notifications. How should I configure the subscription item / notification so that the received message is captured as using the HyperTerminal software?  Is there any documentation we should be aware of?
    Many Thanks,
    Paul Radulescu

    Hi Steve,
    We did our tests this morning. The source socket connection settings are below:
    I also attached a small log (FScan_Gi.txt) around one scan, where the alert is being raised, and the message is being sent to the destination system dummy transaction which only writes the file in the MII Web space (i.e. FS_msg_03.xml)
    My take on the multiple streams is that the scanner we used is a fixed industrial type one. The label being scanned contains multiple barcodes and the scanner scans all of them at once, delimiting the message with some CONTROL CHARACTERS, giving some headaches going forward.
    If I define an XML query and read the message saves "as is" by the dummy transaction above, I get a nice, but firm message :
    which comes from the control characters inserted by the scanner between the barcodes. PCo transmits the message as is, MII saves it as is, but when I try to open and process it .. I can't. Opening it in a transaction in workbench using the text-loader gives me a "prolog" error
    Funny. I feel like I get the best out of it sometimes
    Definitely I have to get rid of those control characters .. even by truncating the message. There are three barcodes being scanned, I presently need only the last one .. so my question is .. Can I use the expression editor and look for the message content after the "~" sign in the string over there (see FS_msg_03.xml) with something like stringpart('Fscan_GI', ~-location, length-of-the-string-after-~) I code below ?
    I have to wait again for the scanner to be available next Tue and test this without copy-pasting the content in the Value box above, but are you envisioning any possible "prolog" errors in the PCo log this time?
    Cheers,
    Paul.

  • Socket.connect

    I'm trying to write a client application that will connect to a server whenever it becomes available. There are some problems which I hope someone will be able to help, Below is a snippet of the code that makes the connection:
    while(alive){
    try{
    /* part 1*/
    Socket s = new Socket();
    s.setReuseAddress(true);
    s.bind(localAddress);
    /* end part 1*/
    s.connect(targetAddress);
    } catch (Exception e){}
    this seems to works fine. However when I place part 1 of the code outside the while loop. the connection will not be made if the server application is up after my connection thread has started running. Isnt Socket.connect suppose to block until a valid connection is made?
    Also when running my application (with the code above) over a long period of time, I get a OutOfMemoryException (native memory) when the server application is not present. Do I have to specify some other parameters for the JVM to release the native resources allocated for a socket construction or is this just a bug? I am running the application using java 1.6 on RHEL4 2.6.9-34.ELSMP.
    Thank you in advance.

    The thread is respawned when then server application
    drops thus yes the socket will only make one
    connection.Not if you move part 1 out of the loop.If you do that you will attempt multiple connections with the socket, which doesn't work.
    Shouldnt the thread block when .connect() fails?Why? Block doing what?
    Instead i'm getting a connection refused exception.What else should it do?
    No i did not close the socket when I get an exception.You should.
    Should the resources be reclaimed since
    the socket object would have gone out of scope?Eventually.
    I'm running my application on a system with multiple
    network cards thus i need to bind it to the intended
    address.Why? TCP/IP will find the best route if you don't get in its way. Why not let it?

  • Reusing socket connection

    I'm trying to write client & server application that needs to keep socket connection alive and be able to use the same socket to do multiple transactions. ( 1 transaction = Request & Response).
    How can the server reliably inform the client about completion of data without closing the socket? The server doesn't know how much data is to be sent before the transaction begins.
    Thank you!

    EJP,
    I'm trying to implement something like HTTP Keep-Alive, in my case it is always turned on.
    Just like a HTTP client, when it sees "Connection: keep-alive" header, it won't terminate the connection even after it has received all data for that particular transaction. I'm looking for the same solution. But I don't know how I can implement it.
    One solution that i can think is, have the server send 0 bytes say for 4 times & when client receives this sequence it will know the transaction has completed, but I'm not sure if this is the optimal solution.
    My situation is very similar to the way HTTP client handles HTTP Keep-Alive connection with Chunked transfer
    Thanks for your response :)

Maybe you are looking for