Connections issue

Im trying to build a very basic server that will allow connections, soon as it receives a message, it sends back the same message (for now, testing purposes)



But the following code, it builds fine, soon as there’s a connection, it quickly closes the connection (program still runs though) and gives the error:



8-Sep-2012 6:39:37 PM com.jme3.network.base.KernelAdapter reportError

SEVERE: Unhandled error, endpoint:NioEndpoint[1, java.nio.channels.SocketChannel[connected local=/127.0.0.1:6143 remote=/127.0.0.1:62542]], context:Envelope[NioEndpoint[1, java.nio.channels.SocketChannel[connected local=/127.0.0.1:6143 remote=/127.0.0.1:62542]], reliable, 21]

java.lang.IllegalArgumentException

at java.nio.ByteBuffer.allocate(ByteBuffer.java:311)

at com.jme3.network.base.MessageProtocol.addBuffer(MessageProtocol.java:142)

at com.jme3.network.base.KernelAdapter.createAndDispatch(KernelAdapter.java:217)

at com.jme3.network.base.KernelAdapter.run(KernelAdapter.java:281)

8-Sep-2012 6:39:37 PM com.jme3.network.kernel.tcp.SelectorKernel$SelectorThread cancel

INFO: Closing endpoint:NioEndpoint[1, java.nio.channels.SocketChannel[connected local=/127.0.0.1:6143 remote=/127.0.0.1:62542]].



Here’s my code:

[java]package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Box;



import com.jme3.network.HostedConnection;

import com.jme3.network.;

import com.jme3.system.JmeContext;

import com.jme3.system.JmeContext.Type;

import com.jme3.network.Server;

import java.io.
;



public class Main extends SimpleApplication {



public static void main(String[] args) throws IOException, InterruptedException {

Main app = new Main();

app.start(JmeContext.Type.Headless);

}



@Override

public void simpleInitApp() {

// *** Open socket and port and listen

try {

Server conn = Network.createServer(6143);

conn.start();

}

catch(IOException ex){ ex.printStackTrace(); }

catch(IllegalArgumentException ex) { ex.printStackTrace(); }

}



@Override

public void simpleUpdate(float tpf) {

//TODO: add update code



}



@Override

public void simpleRender(RenderManager rm) {

//TODO: add render code

}

}

[/java]



ServerListener:



[java]package mygame;



import com.jme3.network.HostedConnection;

import com.jme3.network.Message;

import com.jme3.network.MessageListener;

import com.jme3.network.*;

import com.jme3.network.serializing.Serializable;





@Serializable

public class ServerListener implements MessageListener<HostedConnection> {



public void messageReceived(HostedConnection source, Message m) {



if (m instanceof Message) {

Message msg = (Message) m;

source.send(msg);

source.send(msg);

System.out.println(“MSG RECEIVED / COPIED BACK”);

}

}

}

[/java]

Where do you register the listener? Can we see the real code?



What kind of message are you sending? How is the client sending the message? etc. We only have about 1/8th of the picture here.

This is the real code, its all the code i have for the server, im still somewhat new to this.



Its not even getting to the point of sending a message, soon as there is some sort of connection, it drops the connection and gives that error

(doing a test connection from a telnet)

Well, telnet will send garbage initially so will terminate the connection.



If you want to test networking or work from something that works then please look at the TestChatServer and TestChatClient. The two together show all of the basic aspects of networking in as simple a package as I could do.

Ok, i have gone ahead and checked out testchatserver and client, compiled both, tried to connect locally, soon as i connect through localhost (using testchatclient to connect to testchatserver) i get disconnected immediately and get:



9-Sep-2012 6:27:08 PM com.jme3.network.kernel.tcp.SelectorKernel$SelectorThread cancel

INFO: Closing channel endpoint:NioEndpoint[1, java.nio.channels.SocketChannel[connected local=/127.0.0.1:10502 remote=/127.0.0.1:51546]].



If a friend tries to use the testchatclient to connect on another computer, it locks up their testchatclient entirely but it stays connected until testchatclient gets forced shutdown.



Tried to reverse roles too, him running the server instead, and me running the client, exact same thing.

Figured it out, for some reason you had this in your TestChatClient:



client = Network.connectToServer( TestChatServer.NAME, TestChatServer.VERSION,

host, TestChatServer.PORT, TestChatServer.PORT + 1);



I removed + 1 and it works great. thank you