?
Solved

ServerSocket and UDP

Posted on 1997-05-11
1
Medium Priority
?
1,512 Views
Last Modified: 2008-03-10
Hi,
   Can someone help me with the following problems:
   When I set up a ServerSocket and use a Socket with its stream flag set to true, everything is working fine but once I set the flag to false(ie UDP) there doesn't seem to be a connection... UDP can't be that unrealiabe since I am sending from one window(for serevr) to another(the socket). Where could I have gone wrong?
  Also if I use,eg
   OutputStream outstream = myserver.getOutputStream();
  how much data can I send thru outstream.write(mydata) before mydata is actually send out. Is there a way for me to set the system buffer?
   Is there a Java equivalent to C's union?

   Thanks.


    tm
CHAN
0
Comment
Question by:chantm
[X]
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
1 Comment
 
LVL 6

Accepted Solution

by:
jpk041897 earned 300 total points
ID: 1220361
1) You should be using the DatagramPacket and DatagramSocket classes. Not the Socket class with stram set to false. (this does not invoke UDP, it just stipulates that you do not want a permanent connection beteen th client and the host).

See:

http://www.inf.uni-hohenheim.de/top/java/tutorial/networking/datagrams/definition.html

and

http://www.inf.uni-hohenheim.de/top/java/tutorial/networking/datagrams/clientServer.html

for theory and sample code on how to work with UDP.

2) No way to set the system buffer, but you can set up a counter and call the streams flush() method whenever you want it to.

3) No actual equivalent, since jJava's class (as is C++'s) is related to the struct construct.

Their is a way to do it (though weathr its acceptable for your app or not is debatable).

You can derive a class from java.util.Dictionary

The dictobnary class which maps keys to values. Any object can be used as a key and/or value.  

You could therfore implement either a bag class or add an index to your union (by efectivley converting it into a struct with a union member) and work arrounf the problem.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

650 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