Damjan Vukovic
Damjan Vukovic

Reputation: 21

how to launch java socket-server on remote server

OK, I'm new to server-client applications, and i need some basic information, so forgive me if my question is not clear...

I want to make a chat application that would function like this:

Client A sends information to server, server sends the same information to client B, and vice versa... Think of it as of a simple chat program.

All communication is done through sockets, so i would have a server socket application, and a client socket application... I want my client application to be on my PCs and server application to be on a remote server ( it would be hosted on some free hosting websites).

My question is how do I start that server application on that remote server?

Thanks in advance!

Upvotes: 2

Views: 2677

Answers (5)

noMAD
noMAD

Reputation: 7844

If you are just trying to make a chat client, I don't think you would need an intermediate server. Just connect two machines using server and client sockets

SERVER:

ServerSocketChannel serverSocket;
serverSocket = ServerSocketChannel.open();
serverSocket.socket().bind()
serverSocket.socket().accept()

CLIENT:

SocketChannel clientSocket = SocketChannel.open();
clientSocket.connect();

Of course you would have to use the bind and connect functions properly. Read up on their API's

Upvotes: 1

lxbndr
lxbndr

Reputation: 2208

This tutorial is relatively short, but fully covers basics of Java networking. And it is right about simple chat.

Upvotes: 0

user1034081
user1034081

Reputation: 618

If you're using plain sockets, you should look for some remote server with SSH login. You're able to start your application on the shell then, sth like:

java -jar yourapp.jar

Free hosting websites are rather targeting customers that want to host their website. In my opinion that is not the best choice for hosting a socket application.

For developing purposes, I'd stick with the local machine for the beginning. Running/testing server/client connections on the same machine is much easier as you don't have to work on two different machines, copy code, etc.

Upvotes: 0

antlersoft
antlersoft

Reputation: 14751

Usually, you want an application that is running all the time at your hosting provider (like a web server or perhaps inetd) to start (or embed) your application. The details will be determined by what your hosting provider provides.

Upvotes: 0

SeattleOrBayArea
SeattleOrBayArea

Reputation: 3118

The remote server can be started manually. (If you do not have access to remote server or if you are hosting your server on some third party infrastructure, then they might have a way to do it.)

To be able to start it remotely via some program, you again need a server on the remote machine that listens to this kind of requests.

Upvotes: 0

Related Questions