UDP Instant Messaging Server

Posted on 2004-09-12
Last Modified: 2010-03-31
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??
Question by:AnthonyCosenza
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
  • 4
  • 3
LVL 92

Accepted Solution

objects earned 450 total points
ID: 12040848
if the port is the nedxt token then:
String port = st.nextToken();


Author Comment

ID: 12040870
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
LVL 92

Assisted Solution

objects earned 450 total points
ID: 12040878
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.

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


Author Comment

ID: 12040915
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
LVL 92

Assisted Solution

objects earned 450 total points
ID: 12040930
I see, then you need to lookup the socket for the other client and get the port number.

Author Comment

ID: 12040955

how would this be done??
LVL 92

Assisted Solution

objects earned 450 total points
ID: 12040973
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.

Assisted Solution

gen718 earned 50 total points
ID: 12041253
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?


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
by zero exception 10 79
Given a github repo find email address of all collaborators in that repo 1 51
How to fix  socket closed error 11 59
Firefox and firebub 5 21
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Suggested Courses

740 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