TcpListenerlistener=new(IPAddress.Any,Port);// Allow local comms
listener.Start();
while(true)
{
TcpClientclient=listener.AcceptTcpClient();
// Delegate to another thread
_=Task.Run(()=>
{
AcceptConnections(client);
});
}
// At this point, the ImageCollection will have already been initialised.
// The name of the board will also be set to <boardname>{0}.<extension>.
// Server logic, such as accepting players and maintaining communication goes in here
}
privatevoidAcceptConnections(TcpClientclient)
{
thrownewNotImplementedException();
}
publicvoidInitialiseClient(TcpClientclient)
{
// At this point, no details about the game are loaded; we must load them from the server (to which we have already connected [no data should have been sent]).
// At this point, the minimal amount of work required by the data thread has been done (load all thumbs)
// When an asset is needed from here, queue a load
});
dataLoader.Start();
stateLoader.Start();
byte[]buffer=newbyte[]{0,0,0,1,1};
// Writing to the stream is to be considered near constant-time, but reading is non-constant.
// This application model must be synchronous, but we execute other commands before expecting our response to have arrived (it can complete at any time in that period)
stateStream.Write(buffer,0,buffer.Length);
buffer[0]=1;
buffer[3]=0;
dataStream.Write(buffer,0,buffer.Length);
// A details request is [<uint32, length>, <byte command>]
// The response is about the same format:
varstateResponse=GetResponse(stateStream,4);
vardataResponse=GetResponse(dataStream,4);
// First, load the board state (low mip-map, row definitions, column definitions, zoom position etc.)
// Retrieval command for the board
// Then load the player list, and use the low mip for their sprites
// Then check each loaded image and load the med, then large, then full sprite
// Then load the low of each unused image (for quick retrieval)
}
/// <summary>
/// Idea is that each response is prefaced by a 4 byte stream length specifier.
/// This requires a busy wait to achieve, if not all recieved at once.