- Home /
Low Level API Networking
Hi,
I am trying to develop a car simulator using Unity by playing around with the Roll-a-ball example for exploration. Currently, I am experiencing difficulty sending message to a server end to received a self-defined struct with Unity LLAPIs. I am not able to receive anything from my client. To make things worse, the client will flag "wrong connection" once I start running my server.
For this project, I am using QT for my server while the client end is through Unity.
On the server end (Unity):
// Initializing the Transport Layer with no arguments (default settings)
NetworkTransport.Init();
// Configuring
connectionConfig = new ConnectionConfig();
reliableChannelId = connectionConfig.AddChannel (QosType.Reliable);
// Topology
topology = new HostTopology (connectionConfig, 10);
// Socket creation
socketId = NetworkTransport.AddHost(topology, 10000);
// Connection id creation
byte error;
connectionId = NetworkTransport.Connect(socketId, "127.0.0.1", 10001, 0, out error);
On the client side (QT):
void MainWindow::Start()
{
listener = new QUdpSocket(this);
if(listener->bind(QHostAddress::LocalHost, 10000) == true)
{
qDebug() << "UDP Connected";
connect(listener, SIGNAL(readyRead()), this, SLOT(DisplayData()));
}
else
{
qDebug() << "Error in UDP Connecting";
}
}
void MainWindow::DisplayData()
{
// when data comes in
QByteArray buffer;
buffer.resize(listener->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
if(listener->readDatagram(buffer.data(), buffer.size(), &sender, &senderPort) != -1)
{
Pose_t pose;
pose.deserialize(buffer);
QString valueAsString = QString::number(pose.d_x);
ui->textBrowser->setText(valueAsString);
valueAsString = QString::number(pose.d_y);
ui->textBrowser_2->setText(valueAsString);
qDebug() << "data in ";
// ui->textBrowser->setText(QTextCodec::codecForMib(106)->toUnicode(buffer));
}
}
Thanks.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Check if a player has Network View 0 Answers
Raycasts in Multiplayer Network 0 Answers
Who owns NetworkViews placed in the editor? 1 Answer
[SOLVED]UNET Changing character classes during multiplayer game? 2 Answers