Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualGlass_Knife

Posted 07 February 2013 - 10:18 AM

the server has hold of the clients what? output stream or input stream? and what does the client have a hold of on the server? the servers output stream or input stream?

Don't get confused here. The Java Server Socket library is a wrapper for using TCP/IP networking communication. Any socket, whether a client or server socket, has both an input stream and an output stream. It reads data "in" from the input stream and writes data "out" to the output stream. But the server or client doesn't hold a stream from the other code. You can write a client that talks to a Google server and gets the home page. You have no idea what language or operating system Google is using, and that's the point. The TCP/IP protocol handles all that crap for you so you can just write code. And all the (really) low level code is wrapped up in the ServerSocket library.

If you write data to an output stream, then the server would need to read from the output stream if is held a reference to the same stream. But it doesn't work that way, because that would get really difficult. It is client output the input? This stuff's hard enough without something like that to worry about.

Start you server, and accept() a connection, which will block waiting for someone to connect.
Start your client, and try to connect to the server.
The server's accept() will return, and allow the client to connect.
Now the server reads some data. Since there is no data to read (because the client hasn't sent anything) it will block.

Then the client will be connected, and can send data. After sending data, the client will attempt to read() the response, which will block.
The Server will get the request, do something with it, and return a response. The server then tries to read some more data().

The client then reads the response. And so one. I suggest trying to get a simple client that connects to www.google.com and pulls some data before trying to write the server too. Once you know you've got the client working, if it is broke, it's the server.

Have Fun!

#1Glass_Knife

Posted 06 February 2013 - 01:10 PM

the server has hold of the clients what? output stream or input stream? and what does the client have a hold of on the server? the servers output stream or input stream?

Don't get confused here. The Java Server Socket library is a wrapper for using TCP/IP networking communication. Any socket, whether a client or server socket, has both an input stream and an output stream. It reads data "in" from the input stream and writes data "out" to the output stream. But the server or client doesn't hold a stream from the other code. You can write a client that talks to a Google server and gets the home page. You have no idea what language or operating system Google is using, and that' the point. The TCP/IP protocol handles all that crap from you so you can just write code. And all the (really) low level code is wrapped up in the ServerSocket library.

If you write data to an output stream, then the server would need to read from the output stream if is held a reference to the same stream. But it doesn't work that way, because that would get really difficult. It is client output the input? This stuff's hard enough without something like that to worry about.

Start you server, and accept() a connection, which will block waiting for someone to connect.
Start your client, and try to connect to the server.
The server's accept() will return, and allow the client to connect.
Now the server reads some data. Since there is no data to read (because the client hasn't sent anything) it will block.

Then the client will be connected, and can send data. After sending data, the client will attempt to read() the response, which will block.
The Server will get the request, do something with it, and return a response. The server then tries to read some more data().

The client then reads the response. And so one. I suggest trying to get a simple client that connects to www.google.com and pulls some data before trying to write the server too. Once you know you've got the client working, if it is broke, it's the server.

Have Fun!

PARTNERS