Hot questions for Using Transmission Control Protocol in xml

Question:


Answer:

I don't think that your manifest is the problem, the application package name & Activity name line up with the package keyword of your Activity.

From your dump, it looks like the cause of the exception is your 'network on the main thread' exception. Try moving the network activity to a background thread and see what happens. Making network calls on the main thread has never been a good idea, and the OS throws an exception now whenever you try to do this.

Try an AsyncTask or just try wrapping the actual network call in a runnable and submit it to a background worker thread.

Question:

I'm trying to make a TCP server using netty that runs a TCP Server, listens for incoming xml strings and sends any received xml to all open Connections.

The xml is always formatted the same way (beginning and ending with ).

In addition to handling it's own server connections, it also open a connection with a second server that does the same thing and pools all xml between the two. So basically there's a ServerBootstrap that listens for incoming XML data from any Connection that it listens for as well as one pre-defined connection that the application manages itself.

The two major issues I'm having is

a.) properly listening for data and deliminating incoming strings based on the xml tag. I've tried using XmlDecoder in my pipeline but that doesn't seem to be doing anything. In fact my ServerBootstrap just ends without doing anything, is it supposed to block for listening purposes?

Here's my Server Bootstrap

try {
    ServerBootstrap bootstrap = new ServerBootstrap()
            .group(listenGroup, speakingGroup)
            .channel(NioServerSocketChannel.class)
            .localAddress(new InetSocketAddress("127.0.0.1", mListeningPort))
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                protected void initChannel(SocketChannel ch) throws Exception {
                    ch.pipeline()
                            //.addLast("string-decoder", new StringDecoder())
                            .addLast("xml-decoder", new XmlDecoder())
                            .addLast(new ServerHandler());
                }
            });            
    ChannelFuture channelFuture = bootstrap.bind().syncUninterruptibly();
} finally {
    listenGroup.shutdownGracefully();
    speakingGroup.shutdownGracefully();
}

The other issue im having is establishing a connection to the mirror server and adding it to the list of outputs for the ServerBootstrap. I've done less testing on this myself, and theoretically an interface leading back to a regular ol' Bootstrap should work, but I'm not sure how to keep the Bootstrap connection alive or whether or not it's better to take the Channel somehow and add it to the ServerBootstraps group.

Any thoughts? Sorry if it's a little confusing what i'm trying to do.


Answer:

My guess is that your parenthesis that you are using to delimit your messages isn't supported by the xml decoder. (i.e. you aren't actually sending valid xml) Is there a reason that you can't just use an outermost xml group that holds the entire message?

Question:


Answer:

In your situation it will be better to binary serialize the generated XML and sent it over TCP. Now, lets go through your questions:

  1. How to generate XML , write to it : Use javax.xml package for XML related transformations and binary serialize it.
  2. Send through a Socket in Java(Client): Use java.net package for writing over TCP.
  3. How to receive XML through a Socket and Read it in C# : You can get ByteStream, convert it to String and use XMLDocument.LoadXml(String) to get the XML.