Jump to content
  • Advertisement
Sign in to follow this  
Florian Sch

Telnet Server with JSON

This topic is 2125 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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.)

Share this post


Link to post
Share on other sites

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 ;)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!