|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

05-21-2008, 04:17 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 386
|
|
|
Sockets
I'm writing a program that I want the user to be able to add new connections to other people and listen in for other connections. Is there an easier way to do this.
__________________
My IP address is 127.0.0.1
|
|

05-22-2008, 05:46 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
|
|
I'm not clear what you expecting as an easier way. We can do in regular way we do,
normally I do it in this way.
Socket TestClient;
try {
TestClient = new Socket("Machine name", PortNumber);
}
catch (IOException e) {
System.out.println(e);
}
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-22-2008, 06:30 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 386
|
|
|
the problem is that the other user than has to have a server socket waiting for a connection. Is there an easy way to have a socket that listens for someone to connect to it then make it a normal socket then create another socket that waits for another connection or is there an easier way altogether.
__________________
My IP address is 127.0.0.1
|
|

05-22-2008, 06:46 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
|
|
|
That means you want to open multiple sockets on one side. I think the easiest way to do this is through a thread. Rapidly checking on available connections, we can open existing one. I don't know there is another easy way to do this.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-22-2008, 02:37 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 386
|
|
|
Can I have one socket dedicated to listening for connections to new people then when it finds someone have it make another socket equal to it then have the listening socket waiting for another new connection.
__________________
My IP address is 127.0.0.1
|
|

05-23-2008, 04:30 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
|
|
|
I don't think so. When a socket is communicating, how can it release without destroying the connection.
But I think if you can distribute the time intervals in communicating thread, you can use the socket as another listener. But it's not easy, the numbers of events can handle at a time can be few.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-23-2008, 02:50 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Canada
Posts: 191
|
|
|
Use a server socket. It does exactly what you want. This is how servers work. they listen for connection requests on one port and then create a connection on another port for the client and continue to listen on the original port.
__________________
Daniel @ [ To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. ]
Language is froth on the surface of thought
|
|

05-23-2008, 04:00 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 386
|
|
|
I understand that much about server sockets, but what I want is a client to be able to add new connections from his computer and simultaneously be able to have connections connect to him. Is there a way to do this I'm very new to networking actually I'm just doing this as a way to learn how to use sockets. I have used server sockets and regular sockets before, but all it did was send over a string.
__________________
My IP address is 127.0.0.1
|
|

05-23-2008, 10:45 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 386
|
|
|
What if I made a "Socket" class that had two constructors. The class would have a Socket and a ServerSocket in it. Depending on which constructor I called it would set up the correct one. That way I could have a vector of "Sockets" that in the end where all the same thing. The last Socket in the Vector would be the socket listening in for a new connection. Would this work like I would like or what are your thoughts.
__________________
My IP address is 127.0.0.1
|
|

05-24-2008, 12:44 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Canada
Posts: 191
|
|
|
Hi Zosden,
Before you do anything you have to have clear in mind what the end result is? What do you want to create? A peer to peer chat program? Each client is also a server? My question is how do you know how to find the clients? Usually every peer to peer network is based on some well known servers. The information has to be centralized somewhere. Look at the IRC protocol if you want to know more about chat applications. Everything else is just a refined copy.
__________________
Daniel @ [ To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. ]
Language is froth on the surface of thought
|
|

05-24-2008, 02:50 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 386
|
|
|
This program is just for learning purposes. I just wanted to learn how to use sockets.
__________________
My IP address is 127.0.0.1
|
|

05-26-2008, 05:25 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 386
|
|
|
Is there away to do networking without working on the socket level.
__________________
My IP address is 127.0.0.1
|
|

05-27-2008, 04:27 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
|
|
|
How did you communicate without a socket. I don't think there is another way.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-27-2008, 04:58 AM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 386
|
|
|
I was just wondering if it was possible
__________________
My IP address is 127.0.0.1
|
|

05-27-2008, 05:28 AM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,583
|
|
|
If I found something I'll let you know.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

05-27-2008, 03:20 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Location: Canada
Posts: 191
|
|
|
In Java at higher level you can use RMI.
__________________
Daniel @ [ To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. ]
Language is froth on the surface of thought
|
|

05-27-2008, 05:55 PM
|
 |
Senior Member
|
|
Join Date: Apr 2008
Posts: 386
|
|
|
@ daniel
I don't think that will help me with what I wont to do. I think that if I make a class that has a Socket and a ServerSocket in it then after they have connected to something they can both be used the same way. When I have time I will try it. If I works and I finish I will post my code so everyone can see it.
__________________
My IP address is 127.0.0.1
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|