• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

UDP Instant Messaging Server

As part of the server i need a statement that will return the host name that is given by the client as well as the port of the client the other client asks for.

Here is the snipit of wat i hav so far..

            // Part of if statement to handle "where" command
            } else if (received.startsWith("where")) {
                String host = st.nextToken();
               

                retMes = "@"+host+":"+userport;

wat needs to go in the middle??
0
AnthonyCosenza
Asked:
AnthonyCosenza
  • 4
  • 3
5 Solutions
 
objectsCommented:
if the port is the nedxt token then:
String port = st.nextToken();

0
 
AnthonyCosenzaAuthor Commented:
the thing is the port isnt a token

there is no next token....

all i hav is the client name to get the port number of that client with
0
 
objectsCommented:
then get the port number from thr DatagramSocket.
Why do you need to pass that back to the client anyway? Can't it get it from the socket.

0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
AnthonyCosenzaAuthor Commented:
the way this part works:

1. a client sends a who <username> to server (username bein another client)
2. server looks through to get the host name
3. returns @host:port back to the first client (where host and port are details of the second client)

hope that clears it up
0
 
objectsCommented:
I see, then you need to lookup the socket for the other client and get the port number.
0
 
AnthonyCosenzaAuthor Commented:

how would this be done??
0
 
objectsCommented:
your server would need to keep a mapping for the socket used by each client, allowing the server to look up the socket used by a particular username.
0
 
gen718Commented:
Do you want each client to connect with each other independent of the server once the server responds with the "who" response? Or will all packets go thru the server?

Also, embedding host info in the packets can be a concern. This usually leads to problems when running behind a firewall. Also, are all domain/host names reachable? GetByName might not resolve for private host names.

Just some thoughts. What you think objects?

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now