Solved

ServerSocket and UDP

Posted on 1997-05-11
1
1,508 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 150 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jsp insert to database example 2 64
ejb entity bean example issue 2 27
Glassfish admin console not working 1 60
Java pass by reference 3 22
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

726 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