Sockets

Hi I would like to know if it is possible to send objects over sockets… cause I look through the API it seems that there are no methods that will permit me to do so. Cause I want to send data over the network… for my game. =)

Can anyone enlighten me… :slight_smile:

Thanks

Just wrap your stream (like always) in an ObjectOutputStream - same for ObjectInputStream

new ObjectOutputStream( socket.getOutputStream() );

You might however prefer controlling the bytes your send and receive and in that case Data[In|Out]putStream is good for you - don’t use NIO as of yet :slight_smile:

apache mina can do that. it uses nio.

cough
http://javagamenetworking.dev.java.net
cough

:wink:

Hi Riven…

I tried out your code… but then it seems that my program will hang half way,

is there any kind of explaination? it will say a server timeout after some time…

Thanks!!

don’t forget to flush() your outputstreams

Dont problem is that I cannot even init the object… then the program without throwing any exception just hang there…

so yah i do not know the problem

well… use debugger to see on what line it hangs

I looked at the basic example code and looked quite nice networking wrapper. I did not browse the JGN source code, but wonder how it handles sockets at the server side. Is it non-blocking or traditional thread-per-client server implementation?

Client side does not worry me as it usually has one or two live sockets, but server side is an another story.

Then is there anyway that we can use to handle the problem on the server side?

Just curious.