aspose file tools*
The moose likes Beginning Java and the fly likes Responses from UDP Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Responses from UDP Server" Watch "Responses from UDP Server" New topic
Author

Responses from UDP Server

Ray Zeigler
Greenhorn

Joined: Jul 06, 2012
Posts: 18
Hi Ive made the following program I'm just looking for a little help on how to fix the following:

1)I'm stuck trying to figure out how to supply the listening port number as a command line argument when starting the program.
)For example I want it to ask for a port number when I start the program and use that specified port.


2)The second thing im trying to do is have the server report back a string that tells the client how many integers and non-integer words were in the previous message.
)For example I send the following message from my client to my server "Hi today is July 6"
I want my server to return a string "4 1"
Indicating that the incoming string has 4 non integer words and 1 integer.

Here is my code.




William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

Welcome Pardner,

1. Use the args[] array as specified on the main method.
If args.size() > 0 then you have a command line parameter.
Since this is a String, convert it to an integer (serverPortNumber) and pass it as:


2. Once you receive the packet from the client, tokenize it, using either split() or StringTokenizer
using the space character as a delimiter. now iterate through the tokens, try to convert to an interger,
and catch the illegalNumberFormat exception. Those are strings, else integers. Maintain two counters,
and you're good to go.


Post your code here as you progress.


WP
Ray Zeigler
Greenhorn

Joined: Jul 06, 2012
Posts: 18
Sorry I'm totally new to this. I understand what your saying but I'm unfamiliar with the java syntax.




I get a few errors
Cannot invoke size() on the array type String[]
Syntax error, insert ") Statement" to complete IfStatement
Syntax error on token "if", ( expected after this token
Syntax error on token "myint", invalid Dimensions
This is what I have but I cant compile
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

First of all, you have spread this "task" across multiple forum posts.

It wil make it difficult to have a single thread where you can improve and we can help.

Second, Programming sockets while not knowing even fundamental java syntax,
such as if ( condition) leads me to believe you should step back a little and start small.

I've looked at your other posts and it looks like you are making some progress,
but you have to learn for yourself too, and not expect someone to do it for you.


WP
 
 
subject: Responses from UDP Server