• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

UDP Datagram Connection

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i'm trying to understand this program. I got the drawing part and converting the brush strokes into packets. but i don't get the connection part. (Ultimately when i compile the program nothing comes out. it only displays: Usage: java Draw <my port> <remote host> <remote port>. could someone please verify what is wrong? Million thanks for the help.

As for the connection code i don't get is:
What does this do?



 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The message is telling you that you need to supply arguments.

e.g: java Draw 30000 remote.host 30000

It appears to be sending the local drawings to the remote server.

WP
 
Lucida Romulus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for my lack of knowledge...
how do i supply arguments?
 
William P O'Sullivan
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At command line/prompt whatever:

$ java Draw 30000 127.0.0.1 30001

or

C:\java Draw 30000 127.0.0.1 30001

The application is telling you what it needs !

BTW: It doesn't work. ;)

that's for a later discussion ...

WP
 
Lucida Romulus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i see. thanks for trying it out for me.
i'm not quite sure but is this written in an internet form or a local form....
what if i want to change it such that it connects to a localhost instead...which part should i change?
 
William P O'Sullivan
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The remote host is the server that whatever you draw is sent to.
The remote port is whatever port is it listening on.

Local port is setup on your local running "Draw.class" to listen for responses from server.


Can you even run this, using: java Draw 30000 127.0.0.1 30001

You should get a GUI that allows you to draw things.

WP
 
Lucida Romulus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
after i compile and run it using jCreator it shows



nothing comes out even after i enter the port,remote host and remote port...
the code should be working i think as when i got it i was told it was working and taken from a class lesson.
 
William P O'Sullivan
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no idea what jCreator is doing... but it looks like you are not passing the parameters!

Find the compiled Class file (java.class) and run it from a command line.

jCreator may also have ways to pass program arguments.

When IDEs start to confuse you it is time to either;

1. Learn the IDE (Use the help function)
2. Get a better IDE
3. Go back to basics and use the command line

e.g:


NOTE: I added some System.outs in there to get the thing to run.

WP

 
Lucida Romulus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tested using cmd and this is what i got...


i'm starting to wonder if it is my JDK problem....
you said you added some System.outs in the code, care to share it please?
 
William P O'Sullivan
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you can compile, your JDK is fine.

It looks like you have a major runtime (JRE) problem.

Where is your java installed?

What is the version (java -version) ?

Etc..

You've got issues.

WP
 
Lucida Romulus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i re-installed my JRE and it works using the cmd method. thanks!

However i tried running two of the same application and they don't seem to function the way they are supposed to.

When i draw on one board the other doesn't receive it.
I used these arguments for both windows 30000 127.0.0.1 30001. do i have to alter them?
 
William P O'Sullivan
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CONGRATULATIONS!

No..

You need to run two instances on different ports, e.g:

java Draw 30000 127.0.0.1 30001

and (another cmd prompt)

java Draw 30001 127.0.0.1 30000

WP

 
Lucida Romulus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your help and patience! after posting the question i kinda figured it out and tried it however it did not work...i even created another Draw file and renamed it and tested it. but it still won't send....
could you do me another favor by testing it out please?
 
William P O'Sullivan
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I already did, and hinted that you would have problems with the application early on in the thread.

You DO NOT need to rename or copy anything, simply start two Draws in two different windows
with different parameters, as I've already (patiently) told you.

What are you trying to do?

Do you know Java? I get a sense you are quite new.

Yes, I've tested it, and changed the code to make it work. I can draw in one window and see it in another.

Is this an assignment, a test of some kind to make this work?

For example:

Look carefully through the run() method. Do you see anywhere that message is actually populated with a String??

NO! It's null! and split() throws a NullPointerException!

I do, can and will help, but you have to be honest here as to your capabilities.

WP

Unless this is an interview for me ... ;)
 
Lucida Romulus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry for not stating what i was trying to do at first. Little introduction on my situation:
I know java but i'm not that good in it. i've learned C++, VB, HTML,PHP within 1 year a few years ago in school. The school didn't really care about our knowledge as long as we managed to pass.
End of last year I started JAVA classes(as required by my school) Recently(within this year) I've been given JAVA assignments to do and managed to complete. All which were object oriented programming. All which i did through trial and error(and which was relatively easy), my grasp of JAVA(and other programming) is not good. If the code is easy(doesn't point here and there) i will understand. I've relied on Head-First JAVA book to pass so far.

This is an assignment for a subject called Operating Systems and Networking.
Part 2 of the assignment actually.
Part 1 required me to create a simple instant messenger which i managed to.
Part 2 requires me to select a more complex networking program. I have options, to code it myself(which has extra credit) or to take it from the net(which has less credit, which i intend to do) but to give reference to it. Then i will have to write a detailed report on step by step how does the program work. The reason i ended up doing something like this(whiteboard) was because i was given such a title. The title however, i find is too complex for me. Other titles were taken by my other classmates. I can't appeal to the school because its holiday now. The code was given to me by someone who found it online from some academic archive.

thanks for the help so far, really appreciate it and i hope you will be able to continue to help me.
 
William P O'Sullivan
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the honesty..

Draw.java does not work. You know this right?

You are able to run two instances (on different ports) but they cannot talk to each other.

The networking aspect is easy, send a UDP packet to some server, that server receives it.
UDP has none (if very minimal handshaking).


This example off the "net" seems to be more of a "Make this work" exercise"

From what you posted, I had to make a number of changes. Some are quite significant.

It works and looks quite nice when running though.

I do not think you have the expertise to make this work, maybe you will.

My question again is, what is the deliverable of the assignment? An essay?

WP


 
Lucida Romulus
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Edit: i was not aware that Draw doesn't work until you told me.

There are 2 diff types of deliverable (verbally told by the teacher at least) the teacher is giving us leniency as she knows our programming is weak and we were not scheduled to take this subject until we completed a subject called Data structures or something....but the time table changed and we ended up taking the networking subject first.
Anyway back to the deliverable:

Case 1
If the student wishes to write the code on his own. the code will be ran through a system to check for plagiarism online. If none is found the student is then interviewed by the teacher to ask him to explain the code. eg.like what does this part of the code do? how did you achieve this? if no folly is detected then the student gets marks and doesn't need to write a report.

Case 2(the lenient one)<<the one i'm choosing
If the student can't produce the code himself, he can get it from the internet or the library. However, by doing this the student forfeits a portion of marks and is required to write a report explaining in detail (to prove) that the student understands the code. Edit: the report is an essay.

I found other examples of these type of whiteboard programs but they are even more complex....some are even complete with login systems and broadcast to many users.
I asked the classmate who gave me the code. he gave me the link where he got it from. http://people.dsv.su.se/~vero-rar/java/Draw.java which i am shocked as i don't know what language is that...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic