Advertisement

Telnet Server with JSON

Started by September 19, 2013 09:31 PM
2 comments, last by hplus0603 11 years, 2 months ago

Hi, me and some friends want to create a multiplayergame with Unity3D. But we don´t want to use Unity´s Masterserver. So we created our own Telnet TCP Server. The connection to the server works also the message transfer works. We send messages in JSON format over TCPClient, decode the JSON String stream and decide which method we use. Now our problem is, if we send positiondata each frame to the other player, there is a message overload. Does anyone have an idea how to solve this.


thank you

Two questions:

1. What does "message overload" mean? Specific numbers, please! How big is an update? How often do you send it? How many players? What are the symptoms of the "overload"? On which nodes/machines?

2. How are you separating each message on the TCP stream? In general, the receiving end can't tell where one thing ends and the other starts, unless you first send something like a length field, or terminates each message with a known terminator (like linefeed.)

enum Bool { True, False, FileNotFound };
Advertisement

Here are some more Infos.

I decided to test only to send position Data each second or 2 seconds. the other player receives the data, but the position update only happens each 500 pixels that means the player jumps instead of a continouse movement.

The server is a normal server with the connection type Telnet instead of SSH or ...

With data overload i mean that the position data is sent a way to much so that the "endsystem" can´t work with it in an acceptable time.

In the following you can the the Method how to connect to the Server, how to send position data and how to receive positiondata

void ConnectToServer(TcpClient client, IPEndPoint serverEndPoint)
{
  client.Connect(serverEndPoint);
 
  clientStream  = client.GetStream();
 
  encoder = new ASCIIEncoding();
  buffer = encoder.GetBytes("Hello Server!");
 
  clientStream.Write(buffer, 0 , buffer.Length);
  clientStream.Flush();
}

und hier für das Senden und Empfangen der Position:

public void SendPositionsdaten(float x, float y)
{
  //{"from":1000,"to":[123,234,345],"message":{"cmd":"posupdate","x":1,"y":2}}
  string jsonString = "";
 
  if(username == "usera")
   jsonString = "{\"to\":2,\"msg\":{\"x\":" + x + "}}";
 
  if(client != null && client.Connected)
  {
   //clientStream  = client.GetStream();
 
   //encoder = new ASCIIEncoding();
   buffer = encoder.GetBytes(jsonString);
  
   clientStream.Write(buffer, 0 , buffer.Length);
   clientStream.Flush();
  }
}

if we receive position data we will only use its x value only for testing

public float receivePosition(string jsonBefehl)
{
  var N = JSON.Parse(jsonBefehl);
 
  //string fromVal = N["from"].ToString();
  string toVal = N["to"].ToString();
  string x = N["msg"]["x"];
  string y = N["msg"]["y"];
    float r = 0;
    float.TryParse(x, out r);
    return r;
 
}

hope you can understand my bad english and my problem better now ;)

the position data is sent a way to much so that the "endsystem" can´t work with it in an acceptable time


That's not an answer.

How much is "way too much"? How many kilobytes per second" How many messages per second?
What is "acceptable time"? How do you measure the "work with it time" to compare to "acceptable?"
What kind of packet aggregation or merging do you do on the receiving side?

Looking at your code, you don't do anything to solve #2, though, so your problem is likely that the receive call confuses where the start and end of individual messages are.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement