Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

keeping multiple communication sockets/ports open using siemens TC45 moduke

Posted on 2003-12-03
3
Medium Priority
?
442 Views
Last Modified: 2012-08-14
Hi
 here is an explanation of the problem I am having.
The scenario can be duplicated as follows:

- I have a Main class that starts up a Thread that opens a server socket. The code for the listener thread is as follows:-

/*
 * ListenerThread.java
 *
 *  */

package com.applicationjunction.messenger;
import javax.microedition.io.*;
/**
 *
 * @author  Administrator
 */
public class ListenerThread extends Thread {
 
    private boolean running = false;
    private final Main main;
    //private WorkThread workThread;
 
    /** Creates a new instance of ListenerThread */
    public ListenerThread(Main main) {
        super();
        this.main = main;
    }
 
    public synchronized void start() {
        running = true;
        super.start();
    }
 
    public synchronized void kill() {
        running = false;
    }
 
    public void run() {
        try {
            StreamConnectionNotifier notifier = null;
            StreamConnection connection = null;
            java.io.InputStream is = null;
            java.io.OutputStream os = null;
         
            notifier = (StreamConnectionNotifier) Connector.open("serversocket://:9000",Connector.READ_WRITE,false);
            System.out.println("Waiting for connections on port 9000");
            while (running) {
                // wait for a incoming connection
                connection = notifier.acceptAndOpen();

                System.out.println("Connection received from " + connection.toString());
                os = connection.openOutputStream();
                is = connection.openInputStream();
                System.out.println("Connected to " + connection.toString());
                System.out.println("Sending \"OK\"...");
                // ready to read and write to the stream...
                os.write("ok".getBytes());
                os.flush();
                System.out.println("Message sent.");
                os.close();
                is.close();
                connection.close();
                connection = null;
            }
         
        }   catch (Exception err) {
            System.out.println("Something went wrong with the Listener Thread.");
            err.printStackTrace();
        }
    }
}

This causes the thread to listen for connections on port 9000. This works fine.

- The Main class then opens a socket connection to another module listening on port 9000. The code is as follows:-

        StreamConnection test1 = null;
        InputStream test1in = null;
        OutputStream test1out = null;
        try {
            test1 = (StreamConnection) Connector.open("socket://192.168.0.4:9000",Connector.READ_WRITE,false);
            test1in = test1.openInputStream();
            test1out = test1.openOutputStream();
           
            System.out.println((char) test1in.read());
            System.out.println((char) test1in.read());
           
            test1in.close();
            test1out.close();
            test1.close();
            test1 = null;
        } catch (IOException ioe) {
            System.err.println("Could not receive from other box");
        }

At this point the box is listening for incomming connections and trying to make an outgoing connection to a separate box.
After the socket connection is made, the server socket connection dies with the following stackTrace printout.

java.io.IOException
        at com.sun.cldc.io.j2me.serversocket.Protocol.acceptAndOpen(+4)
        at com.applicationjunction.messenger.ListenerThread.run(+37)

That is all I can give you to replicate the problem. All this is happening over a GPRS connection using the Siemens TC45 device.
I hope you can help me out.

0
Comment
Question by:gregkl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 48

Accepted Solution

by:
Mikal613 earned 1500 total points
ID: 9867054
First Make the Socket Connect and Then and then Listen for incoming connections
0

Featured Post

Introducing the WatchGuard 420 Access Point

WatchGuard's newest access point includes an 802.11ac Wave 2 chipset, providing the fastest speeds for VoIP, video and music streaming, and large data file transfers. Additionally, enjoy the benefits of strong security as the 3rd radio delivers dedicated WIPS protection!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe how to setup a Cisco WLC 5508 to work with Apple's Bonjour protocol across VLANs.  I will also discuss using screen mirroring and Airplay on an AppleTV v3.  This article covers the wireless network only and requires m…
Using in-flight Wi-Fi when you travel? Business travelers beware! In-flight Wi-Fi networks could rip the door right off your digital privacy portal. That’s no joke either, as it might also provide a convenient entrance for bad threat actors.
This Micro Tutorial will show you how to maximize your wireless card to its maximum capability. This will be demonstrated using Intel(R) Centrino(R) Wireless-N 2230 wireless card on Windows 8 operating system.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question