1 Replies - 7615 Views - Last Post: 23 January 2012 - 02:53 AM Rate Topic: -----

#1 made2k  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 8
  • Joined: 25-September 11

question about server communication

Posted 22 January 2012 - 11:56 PM

I am working on a project to create a program that will act as a server and as a client. What the program should do is:

  • Run two instances of the program on two different ports.
  • Initialize a connection from one to the other.
  • Pass information from one to the other (transfer can occur from both).


What I have now (which doesn't quite work) is I create a new thread in the program. That thread has the
socket = server.accept()

line and waits for a connection. I continue to have the original thread connect by inputting the IP and port of the other server, creating a new socket and initializing the outputstream to the new socket.getOutputStream().

The problem I have right now is I run the two programs, they each set up their ServerSockets on different ports. From the main method I am inputting the IP and port of the server I want to connect to. Once I enter that it connects to the other running instance. That instance does not respond to being connected. It still asks for the IP and port to connect to (which I would expect).

So My question, how can I set up server/server communication. I need to be able to pass information on the command line for which server to connect to. I do not need code necessarily but an explanation on how to go about this or reference articles. I've already looked at many articles explaining client/server communication.

Is This A Good Question/Topic? 0
  • +

Replies To: question about server communication

#2 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1156
  • View blog
  • Posts: 2,538
  • Joined: 05-May 05

Re: question about server communication

Posted 23 January 2012 - 02:53 AM

1. It would help greatly to see your code.
2. Unless the server is expected to handle multiple clients, there's absolutely no need for threads. Don't complicate things.

Quote

The problem I have right now is I run the two programs, they each set up their ServerSockets on different ports


3. The server should be using a ServerSocket, and the client should b using a Socket.
4. The Java tutorials (google it) has client/server tutorials and pbl has one here.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1