creating server !
How do we create a simple server?
We can create a simple server if we do the following:
server_socket = new ServerSocket( 5050, 100,
InetAddress.getByName("127.0.0.1"));
look those statements from a tutorial..
where is server ? a language can create a server !!!.......whats happening in this code ?
hi,....is itconnecting to a server orcreating a server ?
N.B : i guess there is a server somewhere in the network.....it is just connecting to it through port 5050(bcoz a server has got many ports)
plz remove my confusion.
its related to 2- tier Client-Server application.
i dowloaded 2 code(+batch files)...those are 2-tier Client-Server application.
there wasClient Application ( JFrame ) and another was Server Application (JFrame ).
What concerns me is that the Port No 5050 and 127.0.0.1.....are these Number for any real physical server machine . ?
> What concerns me is that the Port No 5050 and
> 127.0.0.1.....are these Number for any real
> physical server machine . ?
5050 is arbitrary -- any number would work so long as the client and server agreed on it. (Some operating systems restrict the use of ports below 1024, but that isn't a problem here.)
127.0.0.1 means "this computer" -- whatever computer you are running it on.
> 5050 is arbitrary -- any number would work so long as
> the client and server agreed on it. (Some operating
> systems restrict the use of ports below 1024, but
> that isn't a problem here.)
>
> 127.0.0.1 means "this computer" -- whatever computer
> you are running it on.
ok......got releived....those numbers was suspecious!!
ok...thanks
ServerSocket(int port, int backlog, InetAddress bindAddr)
Create a server with the specified port, listen backlog, and local IP address to bind to.
can u tell what is the meaning of backlog ? its value has been assigned to 100.
> server_socket = new ServerSocket( 5050, 100,
> InetAddress.getByName("127.0.0.1"));
> 0.0.1"));
>
> look those statements from a tutorial..
>
> where is server ? a language can create a server
> !!!....... whats happening in this code ?
>
> hi,....is it connecting to a server or
> creating a server ?
>
> N.B : i guess there is a server somewhere in
> the network.....it is just connecting to it through
> port 5050(bcoz a server has got many ports)
Nope. The above code does create a server. It's not a very useful server (unless there's more code that you haven't shown us). But in the simplest case, by a relatively lenient definition, a server is just something that listens for requests. Well, the above code will allow clients to connect on port 5050. (Actually, I think we need one more thing--a call to Socket socket = server_socket.accept();.)
Now, if you put the accept call in there, then a client can open a connection. But (unless there's additional code), that's all this server does.
A "real" server would put socket in a collection of client sockets, and either spawn a thread or pull one from a pool that reads and services requests and writes responses on that socket.
> can u tell what is the meaning of backlog ?
> its value has been assigned to 100.
Read the docs. It's something like how many requests can pile up waiting for (I think) the accept call. If there are 100 waiting, and number 101 comes it, it will be told, "I can't service you now."
Or thereabouts.
what a language !.....charming. Ok.....very much satisfied. thanks
> what a language !.....charming.
> Ok.....very much satisfied. thanks
Just to clarify: The ability to create a server (or server socket) is not part of the language. It's part of the core APIs. In other words, it's a library that somebody at Sun wrote using the Java language and some C/C++ that it hooks into through JNI.
The C/C++ piece in turn makes function calls like socket, listen, and accept on libraries that come with those languages' compilers or come bundled with the OS.
These libraries in turn probably call lower level functions provided by the OS, which in turn access the memory and/or other hardware that is your 'puter's network interface.
Approximately.