Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client-to-Client networking...

Status
Not open for further replies.

grande

Programmer
Feb 14, 2005
657
CA
Hello,

I'm trying to establish a Client-to-Client connection over Java. I'd like to avoid having a seperate Server application (if possible). You'll have to forgive me, I'm fairly new to Java.

If anyone could offer any advice/resources, I'd really appreciate it.

Code:
public static void main(String args[]) {
   NetworkConnection NCClass = new NetworkConnection();
   NCClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   String ipadd = "127.0.0.1";
   int portnum = 6000;
   try {
      Socket sock = new Socket(ipadd, portnum);
      BufferedReader input = new BufferedReader(new InputStreamReader(sock.getInputStream()));
      PrintWriter = output = new PrintWriter(sock.getOutputStream());
      
      System.out.println("Connection established to " + sock.getInetAddress());
   }
   catch (IOException e) {
      System.out.println("Connection Lost " + e);
   }        
}

What I'm hoping to happen is someone will create an instance of my class (NetworkConnection nc = new NetworkConnection(ipaddr, portnum)), which would open the connection to another computer.

If you could offer me any help at all, whatsoever, I'd be very appreciative.

-------------------------
Just call me Captain Awesome.
 
But then the other computer will act as a server, I don't fully undertand what you're trying to do.

Cheers,
Dian
 
After looking around, it looks like I'll have to have two classes (One client/send, and one server/receive). Is this correct?

-------------------------
Just call me Captain Awesome.
 
That's pretty much a client-server schema, right.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top