Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-21-2008, 04:17 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Rep Power: 2
Zosden is on a distinguished road
Default 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
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 05-22-2008, 05:46 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
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.

Code:
    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.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-22-2008, 06:30 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Rep Power: 2
Zosden is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-22-2008, 06:46 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
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.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-22-2008, 02:37 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Rep Power: 2
Zosden is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-23-2008, 04:30 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
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.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-23-2008, 02:50 PM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 191
Rep Power: 2
danielstoner is on a distinguished road
Default
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 @ [www.littletutorials.com]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-23-2008, 04:00 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Rep Power: 2
Zosden is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-23-2008, 10:45 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Rep Power: 2
Zosden is on a distinguished road
Default
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
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 05-24-2008, 12:44 AM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 191
Rep Power: 2
danielstoner is on a distinguished road
Default
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 @ [www.littletutorials.com]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 05-24-2008, 02:50 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Rep Power: 2
Zosden is on a distinguished road
Default
This program is just for learning purposes. I just wanted to learn how to use sockets.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 05-26-2008, 05:25 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Rep Power: 2
Zosden is on a distinguished road
Default
Is there away to do networking without working on the socket level.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 05-27-2008, 04:27 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
How did you communicate without a socket. I don't think there is another way.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 05-27-2008, 04:58 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Rep Power: 2
Zosden is on a distinguished road
Default
I was just wondering if it was possible
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 05-27-2008, 05:28 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,513
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
If I found something I'll let you know.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 05-27-2008, 03:20 PM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 191
Rep Power: 2
danielstoner is on a distinguished road
Default
In Java at higher level you can use RMI.
__________________
Daniel @ [www.littletutorials.com]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 05-27-2008, 05:55 PM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Rep Power: 2
Zosden is on a distinguished road
Default
@ 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
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending files over sockets! rameshraj Networking 2 05-30-2008 11:18 PM
An echo server using UDP sockets Java Tip java.net 0 04-07-2008 09:09 PM
Sending Mail Using Sockets Java Tip java.net 0 04-07-2008 09:05 PM
how to send files through sockets gabriel Advanced Java 3 01-12-2008 09:10 AM
Help with Sockets Eric Networking 3 12-01-2007 09:09 PM


All times are GMT +2. The time now is 10:55 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org