How to declare IP for server run?

hello,



as i see “Network.createServer” dont have method to declare IP for a server. it is running on all IP’s.

I can declare only port as i see…

Is there possibility to run server on declared IP?

The server runs using the ip of the machine where it is created.

If you try to run a networking game in a LAN for example you need to start the server at a determined tcp and udp port and then start a client on another machine creating a net client that connects to the ip of the pc the server is running on. To know the ip simply start a console on the server’s pc ad type:



Windows → “ipconfig /all”

Linux → “ifconfig”



And than start the client application with the specified ip

:slight_smile:

@kazeshiro said:
The server runs using the ip of the machine where it is created.
If you try to run a networking game in a LAN for example you need to start the server at a determined tcp and udp port and then start a client on another machine creating a net client that connects to the ip of the pc the server is running on. To know the ip simply start a console on the server's pc ad type:

Windows -> "ipconfig /all"
Linux -> "ifconfig"

And than start the client application with the specified ip
:)

we know this all,
my question is diffrent:

Is there possibility to run server on declared IP? Server have MANY IP's, and we try to run one IP from pool

edit:

and another question: we dont want to use UDP to connect, becouse we all traffic migrate with TCP proxy only(becouse this is needed by network infrastructure).

so how to use only TCP?

Ok, sorry me.



I thought you were a newbi of spidermonkey.

I don’t know how to declare a server that get a specified ip but for the question about TCP i think that you cloud simply use only reliable messages and ignore the UDP protocol.



I hope I’ve been of some help :slight_smile:

1 Like
@kazeshiro said:
Ok, sorry me.

I thought you were a newbi of spidermonkey.
I don't know how to declare a server that get a specified ip but for the question about TCP i think that you cloud simply use only reliable messages and ignore the UDP protocol.

I hope I've been of some help :)


impossible:
[java]
public static Server createServer( int port ) throws IOException
{
return createServer( DEFAULT_GAME_NAME, DEFAULT_VERSION, port, port );
}
[/java]
that is why... when you set one port, it create same port for UDP and TCP. i tried to use -1 / etc. nothin help

but maybe there is some method after initialization, so i need author or someone who know, to answer me.

[java]public static Server createServer(int tcpPort,

int udpPort)

throws java.io.IOException[/java]



In the Network class there is this method. This can help you?

im happy you want to help, but you dont help, it is like “do you know where is my dog?” and you answer " that dog is not a cat. maybe this will help you"



edit:



to be more precision, i have 2 questions(still not solved):


  1. Is there possibility to run server on declared IP? Server have MANY IP’s, and we try to run one IP from pool


  2. We dont want to use UDP, becouse we all traffic migrate with TCP proxy only(becouse this is needed by network infrastructure). so how to use only TCP?
it is like “do you know where is my dog?” and you answer ” that dog is not a cat. maybe this will help you”

XD

Ok. I don't understand where is the problem. If you don't want to use UDP protocol, why can't you use only TCP messages??
If you don't send UDP messages the UDP connection is not used. So it need only to declare a Message the is always reliable and it will be sent over the TCP protocol

when i use only TCP messages like this:



[java]message.setReliable(true)[/java]

  • or in constructor just

    [java]setReliable(true)[/java]



    it give


2012-01-27 14:33:44 com.jme3.network.base.DefaultClient handleError
SEVERE: Termining connection due to unhandled error
com.jme3.network.kernel.ConnectorException: Error reading from connection to:[hidden ;)]
at com.jme3.network.kernel.udp.UdpConnector.read(UdpConnector.java:129)
at com.jme3.network.base.ConnectorAdapter.run(ConnectorAdapter.java:159)
Caused by: java.net.PortUnreachableException: ICMP Port Unreachable
at java.net.PlainDatagramSocketImpl.receive0(Native Method)
at java.net.PlainDatagramSocketImpl.receive(Unknown Source)
at java.net.DatagramSocket.receive(Unknown Source)
at com.jme3.network.kernel.udp.UdpConnector.read(UdpConnector.java:120)
... 1 more


on serwer was blocked UDP, when its unblocked, then it work. but finally it need to be blocked in our infrastructure

You do not need to use the UDP connection, you can even close it altogether by specifying port “-1” for it.

To make a server with a specific address without UDP do this:

[java]

InetSocketAddress = new InetSocketAddress(“192.168.1.1”, tcpPort);

SelectorKernel reliable = new SelectorKernel(inetAddress);

Server server = new DefaultServer( gameName, version, reliable, fast );[/java]

But its not necessary really, the server will listen on all addresses anyway.

[java]

InetSocketAddress inetAddress = new InetSocketAddress(IP, tcpPort);

SelectorKernel reliable = new SelectorKernel(inetAddress);

InetSocketAddress inetAddress2 = new InetSocketAddress(IP, -1);

SelectorKernel fast = new SelectorKernel(inetAddress2);

server = new DefaultServer("castway", 1, reliable, fast );

[/java]


Exception in thread "main" java.lang.IllegalArgumentException: port out of range:-1
at java.net.InetSocketAddress.(Unknown Source)
at cwserver.DatabaseServer.initServer(DatabaseServer.java:211)
at cwserver.DatabaseServer.main(DatabaseServer.java:239)



or like this:

[java]
server = Network.createServer("castway", 1, tcpPort, -1);
[/java]


2012-01-27 14:49:43 com.jme3.network.kernel.tcp.SelectorKernel$SelectorThread connect
INFO: Hosting TCP connection:0.0.0.0/0.0.0.0:33001.
Exception in thread "main" java.lang.NullPointerException
at com.jme3.network.base.DefaultServer.start(DefaultServer.java:159)
at cwserver.DatabaseServer.initServer(DatabaseServer.java:209)
at cwserver.DatabaseServer.main(DatabaseServer.java:233)
2012-01-27 14:49:43 com.jme3.network.kernel.tcp.SelectorKernel$SelectorThread run
INFO: Kernel started for connection:0.0.0.0/0.0.0.0:33001.


tests done with blocked UDP on server infrastructure. only TCP allowed

btw we tried to have all messages have "setReliable(true);", but it dont work too.

i think somethin is using UDP here, becouse when UDP is unblocked, it work. but i repeat: we need finally to have blocked UDP on server infrastructure

Just do what I said. Either you use the static Network.createServer() with port -1 or do what I posted. Specifying an InetAddress with port -1 is wrong.

[java] InetSocketAddress inetAddress = new InetSocketAddress(IP, tcpPort);

SelectorKernel reliable = new SelectorKernel(inetAddress);

Server server = new DefaultServer(“castway”, 1, reliable, fast );[/java]



sorry @normen you are best, becouse you solved problem with IP (point one), but there is problem with your code, there is not fast variable.



edit:

[java]server = Network.createServer(“castway”, 1, tcpPort, -1); [/java]

tried before. i posted exception i get from it

null

with null:


2012-01-27 15:07:21 com.jme3.network.kernel.tcp.SelectorKernel$SelectorThread connect
INFO: Hosting TCP connection:/[hidden :)]:33001.
Exception in thread "main" java.lang.NullPointerException
at com.jme3.network.base.DefaultServer.start(DefaultServer.java:159)
at cwserver.DatabaseServer.initServer(DatabaseServer.java:219)
at cwserver.DatabaseServer.main(DatabaseServer.java:243)
2012-01-27 15:07:21 com.jme3.network.kernel.tcp.SelectorKernel$SelectorThread run
INFO: Kernel started for connection:/[hidden :)]:33001.

:facepalm:

[java]Server server = new DefaultServer("castway", 1, reliable, null );[/java]

Having no UDP port will only fail if you then use it afterwards.

1 Like

[java] InetSocketAddress inetAddress = new InetSocketAddress(IP, tcpPort);

SelectorKernel reliable = new SelectorKernel(inetAddress);

server = new DefaultServer("castway", 1, reliable, null );[/java]



yes i done like this :wink:



dont do facepalm before test :stuck_out_tongue:





edit: remember, my tests are done on network architecture with blocked UDP

Well if those lines of code crash for you then you live in one of those parallel universes some of our users seem to live in and I cannot help you. Else what I said counts: It only fails if you then try to send unreliable messages.

1 Like

btw you helped me with first question about IP, so i thank you very much :slight_smile:



and i still looking for only TCP solution for me. maybe this is version problem? should i use nifty or standard libraries?



maybe @pspeed will know :slight_smile:

:brainsout: … there is no UDP in the code I posted

1 Like