Master the Jxta shell, Part 1

Gain hands-on Jxta experience with the interactive Jxta shell

1 2 Page 2
Page 2 of 2

The pipe advertisement created by the above command does not denote a secure pipe. All messages passing through such a pipe are unencrypted, and any sniffers placed on the network can easily detect them. So if you intend to have a truly secure conversation, you must use:

JXTA>talk -register myNick -secure

In this case, the pipe advertisement created is for a secure pipe that passes encrypted messages. On the flip side, your chat might become slower -- obviously, that's the penalty you pay for increased security.

Alternate method

To create a pipe advertisement with an alternate method, you must use the mkadv command with the -p option.

JXTA>chatPipeAdv = mkadv -p

Create the pipe

Use the talk command

The next step is to log in to the chat, which actually entails creating a pipe out of the advertisement that you created in the previous step. Not only that, but when you log in, you also listen to this newly created pipe:

JXTA>talk -login myNick

Alternate method

To achieve the same effect using shell commands, you must create an input pipe. For this, use the mkpipe command:

JXTA>inpPipe = mkpipe -i chatPipeAdv

Send a message

Use the talk command

Try sending a message to yourself first:

JXTA>talk -u myNick myNick

Don't forget to end your message with a period (.).

To talk to other users, you need to search for them on the Jxta network. To search, use the talk command with the search option:

JXTA>talk -search

Alternate method

To send a message through a pipe with a shell command, you must first create a message object:

JXTA>chatMessage = mkmsg

Right now the message is blank and lacks data. To handle the message's data portion, create a simple text file called hello.txt containing the string "Hello Pipe Talk". Then, import this text file's contents into a shell object called chatMessageText:

JXTA>importfile -f d:\hello.txt chatMessageText

That command creates a chatMessageText object containing your message. Now you need to put this data into your message object:

JXTA>put chatMessage messageTag chatMessageText

The messageTag is the name of the tag associated with the message.

To send the message, first create an output pipe:

JXTA>outPipe = mkpipe -o chatPipeAdv

Once you have an output pipe, use the send command to send the message:

JXTA>send outPipe chatMessage

Now comes the difference between the shell command pipe chat and the talk command pipe chat. The talk -login command not only creates a pipe but also listens to it; however, the shell command pipes are not being listened to for any message. Use the recv command to listen to an existing input pipe:

JXTA>message =recv inpPipe

Here, the shell listens to the input pipe inpPipe. Whatever message the input pipe receives is put in the message object. Note that the recv command is a blocking command. However, you can specify a timeout for this command by using a -t option.

To retrieve the transmitted text from the message object, use the get command:

JXTA>messageText = get message messageTag

Finally, print the contents to the shell console using the cat command:

JXTA>cat messageText

Run multiple peers

The straightforward way to run multiple peers is to use different machines that are all connected to the Jxta network. In most cases, however, you would probably prefer to use your own machine to run multiple peers. To do that, make a copy of the JXTA_Demo folder in a different location. Launch the shell.exe in this folder's shell subdirectory. Make sure that your shell is running.

However, this approach has a small problem. When you copy the JXTA_Demo folder, you also copy all the configuration information you provided for the first shell. But you need to reconfigure the second peer to make it work properly. To do this, after launching the shell, type peerconfig followed by exit. Relaunch the shell to receive the Jxta Configurator window. You might want to change the peer name. Although peer names don't have to be unique in the network, it might be easier to keep track of your peers if they have different names. What you do need to change is the HTTP and TCP/IP settings in the Advanced tab. Change the port numbers for both these transports. For example, change the HTTP port number 9700 to 9710 and the TCP port number 9701 to 9711. This change ensures that both peers do not use the same ports. Click OK to run both peers.

Get cracking with the Jxta shell

In this article, we explored all the rudiments you need to get started with the Jxta shell, namely installation, configuration, and the shell environment. We also looked into some simple shell commands. The shell features many more commands not discussed in this article; use the man command to explore them.

Remember that the shell commands are nothing but Java programs running in the Jxta shell context. In the next article, we'll look into the shell internals. You will also learn to write your own shell commands, which can help you build complex applications running over the Jxta shell.

Navaneeth Krishnan is senior product engineer at Aztec Software and Technology Solutions. He has designed and developed several e-commerce solutions and frameworks for clients at Aztec. He is an active P2P enthusiast and currently developing a framework over Jxta. He is also cowriting an upcoming Jxta book.

Learn more about this topic

1 2 Page 2
Page 2 of 2