I am creating my game server with java nio, But i can not find how to use socketchannel or send data in c#, how can I solve this problem. Just use i/o?
Asked
Active
Viewed 427 times
1
-
Assuming you would like to do this synchronously there is an example on how to use Sockets for synchronous communication on MSDN : https://msdn.microsoft.com/en-us/library/kb5kfec7(v=vs.110).aspx – Irwene Jan 18 '17 at 10:45
-
I herd that nio does not use stream type but it does not makes any matter? – whtjs Jan 18 '17 at 10:48
-
2As long as you send your payload in a format both languages can understand, it is irrelevant if java uses NIO and C# something different. Point is: You send bytes over well probably TCP - right? So you can use your preferred method for sending / receiving bytes. You only need to have a decent protocol. Be it some byte-protocol you invented yourself or some standards like JSON, Xml, ... to be able to serialize / deserialize your payload. – Fildor Jan 18 '17 at 10:53
-
Speaking of a **game** server, you should consider the needed throughput and reliability, though. For example if you have like a first-person-shooter, you will probably like to use UDP with a very simple protocol, because it does not matter that each single packet arrives, but they should be exchanged on a very high frequency. – Fildor Jan 18 '17 at 10:58
-
@Fildor thanks a lot !! I think know i understand what is the point. I will try it – whtjs Jan 18 '17 at 11:08
1 Answers
0
Object communication through sockets has many limitations. You have to define some kind of communication protocol to understand data on both sides. You can also send serialized data ensuring that deserialization is done in the same way on the other side. You should use some other mechanism such as WebServices (SOAP or RESTful) for ease of use.
-
1I like to use the websocket + json combination when sending data between on network between application using different languages. Both of these are pretty well supported on many of the mainstream languages – Irwene Jan 18 '17 at 10:56
-
@Sidewinder94 OP is speaking of a **game** server. So choice of technologies will highly depend on the type of data to be exchanged. – Fildor Jan 18 '17 at 11:00
-
@Fildor I completely agree, It was just meant as a starting point, not as a full blown miracle solution ^^, I may not have expressed it correctly though. – Irwene Jan 18 '17 at 11:06
-
Thanks for your advice!! But is there any benefit by splitting the server like that?? – whtjs Jan 18 '17 at 11:16