Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Java networking

Posted on 2002-07-07
10
Medium Priority
?
214 Views
Last Modified: 2010-03-31
Hi All
Can I open TCP or UDP connection to a server and identify my self as other IP address? I want to write a simple unit test for my application that need to send packets from some resources, can I do it in java? is there anyt way doing it?
   Thanks
0
Comment
Question by:dannysh
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 2

Expert Comment

by:nir2002
ID: 7134810
Hi Danny,

Although I have not try, for both TCP,UDP have constructors
that get the local address:

UDP
===
public DatagramSocket(int port,
                      InetAddress laddr)
               throws SocketException

Creates a datagram socket, bound to the specified local address. The local port must be between 0 and 65535 inclusive.

TCP
===
public Socket(InetAddress address,
              int port,
              InetAddress localAddr,
              int localPort)
       throws IOException
Creates a socket and connects it to the specified remote address on the specified remote port. The Socket will also bind() to the local address and port supplied.

Although I am not certain that the TCP will work as you expected since it reliable protocol and the communication need feedback.

Best regards
Nir
0
 
LVL 3

Accepted Solution

by:
yasser_helmy earned 160 total points
ID: 7134816
No. The ip addr. is automatically written in the socket. You cant modify it.
But if you want to test the server and client on the same machine, you can use two different ports. For example, the server uses port 8000 and the client uses port 9000.
0
 
LVL 2

Expert Comment

by:nir2002
ID: 7134819
so why there is an option for local address?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:dannysh
ID: 7134845
I think Nir is right in his question. I will test your solution.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7135296
>>Creates a socket and connects it to the specified remote address on the specified remote port. The Socket will also bind() to the local address and port supplied.

Only if you own that address.

What you're trying to do is spoof your IP address. This could only be done with JNI. It requires low-level access to do this. ASFAIK, in Windows, low-level would mean *below* the Win API.
0
 

Author Comment

by:dannysh
ID: 7135306
Hi CEHJ
So what is the meaning of local address in the socket constructor?
0
 
LVL 92

Expert Comment

by:objects
ID: 7136379
Its used in cases where your box has more than one IP addesses, such as if it has more than one network card.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7136387
>>Its used in cases where your box has more than one IP addesses, such as if it has more than one network card.

Strange - I've posted exactly the same thing - but it didn't appear!?
0
 
LVL 35

Expert Comment

by:girionis
ID: 8894125
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- points to yasser_helmy

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0

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.

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…
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…
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

783 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