documentation I was reading
it is written: public Task<SocketMessage> SendReceiveAsync(SocketMessage query)
in source code is: public async Task<SocketMessage> SendReceiveAsync(SocketMessage query){...}
what I'm trying to understand is how do I call it and how it works. anything I try I get errors.
what I'm trying to do is send and receive message from server. I've been working on this for weeks now I've been also reading How and when to use ‘async’ and ‘await’ but I can't manage to get it work.
this is what I managed to make.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Stride.Core.Mathematics;
using Stride.Input;
using Stride.Engine;
using Stride.Engine.Network;
using System.IO;
namespace MyGame
{
public class Net : SyncScript
{
string str = "";
public Stream socket;
public SimpleSocket SS;
public SocketMessage SM;
public SocketMessageLayer SML;
public void Server(){
SML = new SocketMessageLayer(SS, true);
//int port, bool singleConnection, int retryCount = 1
SS.StartServer(21, true, 1);
}
public void Client(){
SML = new SocketMessageLayer(SS, false);
//string address, int port, bool needAck = true
SS.StartClient("127.0.0.1", 21, true);
}
Task<SocketMessage> SendReceiveAsync(SocketMessage query){
//here I need to return somehow as I get error: not all code paths return a value
return query; // Error: Cannot implicitly convert type 'Stride.Engine.Network.SocketMessage' to 'System.Threading.Tasks.Task<Stride.Engine.Network.SocketMessage>'
}
public async Task ReceiveMessage(){
// you still need to get the query from somewhere...
SocketMessage result = await SML.SendReceiveAsync(SM);
//[abbreviated] // if I uncomment this I get: Error: ; expected
//Error: Invalid expression term '}'
}
public override void Start(){
}
public override void Update()
{
}
}
}
EDIT: inside code I've explained what I tried and what doesn't work