Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment   Page 7 of 7     «   Prev   4   5   6   7
ryleyra

Registered:
Posts: 3,009
Reply with quote  #91 
All right, I know I'm missing something. I used your example on the ArtClientLib wiki to create a proxy, but it breaks down the moment I try to turn it into a proxy that accepts multiple clients. You were talking about that earlier in the thread, so I'm assuming there's a way to do it, I'm just missing it. So any advice on what I am supposed to do?

What I'm hoping is to eventually create a bunch of "passthrough" proxies, and run a separate controller on a specified host and port. The controller will then have a list of ships, and will direct the proxies to disconnect the clients from their own server and reconnect to another. That should work as a first step.

My problem is that I need to have some way to associate a set of clients with their server. I can't just have all the clients connect to one proxy, the proxy wouldn't be able to tell which is their "home" server. So I'm starting with the proxy, which will just manage one ship, and adding the controller once that's working.
Arkantos

Avatar / Picture

Registered:
Posts: 457
Reply with quote  #92 
The proxy example shown in the wiki accepts a single connection. As soon as it receives that connection, it stops listening for more. The important part, the one that actually handles the connections, looks like this (simplifying the wiki example somewhat):

ServerSocket listener = new ServerSocket(this.port, 0);
listener.setSoTimeout(0);
Socket skt = listener.accept();
ThreadedArtemisNetworkInterface client = new ThreadedArtemisNetworkInterface(skt, ConnectionType.CLIENT);
ThreadedArtemisNetworkInterface server = new ThreadedArtemisNetworkInterface(serverAddr, serverPort);

The listener.accept() command is the one that actually blocks to wait for a new client connection. Once the client connects, the next line connects that socket to the protocol handling stuff. The line after that opens a new connection to the server. So you have two ThreadedArtemisNetworkInterface objects, one to the client and one to the server, and anything that comes in on one you will have to pass to the other.

Once a connection is received, accept() unblocks and no longer listens for connections. In order to listen for more connections, you'll have to put the connection handling code in a loop.

There are a couple of different ways to go about handling proxy connections to multiple servers. In any case, what you'll probably want to do is have each server have a different port on the proxy assigned to it. That way, the server a client connects to is dictated by the port to which it connects on the proxy. You can do this either by making your proxy launch a separate thread for each listener port (so that it can listen on multiple ports simultaneously), or by simply running multiple instances of the proxy, each one listening on a different port.

Hope this helps.

ryleyra

Registered:
Posts: 3,009
Reply with quote  #93 
Well, I tried putting it into a loop, but it doesn't seem to work. The first client connects fine, and the second appears to connect to the proxy okay, but the client doesn't acknowledge that it connected, and says "connection failed" once it times out. Then when you try to connect again, the proxy throws an exception and reports "the socket is closed".

Is the problem that the proxy needs to connect to the server on a different port for each connection? I'm using the same ThreadedNetworkInterface each time, with a different one for each client. Maybe I'll try creating a new socket to the same host and port for each.

I did think of using port to identify the client's server and ship. However, this requires modification of the artemis.ini file, and what I'm trying to do is streamline the process of setting up the War Server and making it user friendly. So I want to assume the users haven't changed anything, and are all on different machines. (Although they could use a different port to run the proxy and server on the same machine)

EDIT: That worked. The problem was I was trying to cram all the traffic through one socket. [biggrin] Creating a separate server connection for each client connection fixed it.

Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.