-
-
Save kou-yeung/984d43706ab1787691004600a3cc142f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ユーザのセッション情報 | |
// TcpListenerにアクセス要求が来たときに作成されます | |
using System; | |
using System.Net.Sockets; | |
public class Session | |
{ | |
TcpClient client; | |
NetworkStream stream; | |
Action<Session, Command> commandExec; | |
public Session(TcpClient client, Action<Session, Command> commandExec) | |
{ | |
this.client = client; | |
this.stream = client.GetStream(); | |
this.commandExec = commandExec; | |
} | |
public void Poll() | |
{ | |
while (client.Available > 0) | |
{ | |
Command cmd; | |
if(TryParseCommand(out cmd)) | |
{ | |
commandExec(this, cmd); | |
} | |
} | |
} | |
bool TryParseCommand(out Command cmd) | |
{ | |
// stream -> Command : 今回は解説しない | |
return true; | |
} | |
public void Send(byte[] bytes) | |
{ | |
stream.Write(bytes, 0, bytes.Length); | |
stream.Flush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment