Solved

Java networking

Posted on 2002-07-07
10
175 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
10 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 40 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
 

Author Comment

by:dannysh
ID: 7134845
I think Nir is right in his question. I will test your solution.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groovy example issue 10 90
Starting to learn JAVA, 7 59
Java passing arguments (type error) 2 48
JUnit 4 @Before and @BeforeClass differences 3 48
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now