서버 클라이언트 응용 프로그램이 있습니다. 서버와 클라이언트는 TCP와 스트림을 사용하여 파일을 송수신 할 수 있습니다. 파일 전송이 같은 내 수업에서 자신의 스레드를 가지고 리스너에서 처리됩니다스레드 수신기에 인수 전달
static void Main(string[] args)
{
Thread thread = new Thread(new ThreadStart(Listen));
thread.Start();
}
그리고 듣기 방법 (간체) :
private static void Listen()
{
using (TcpClient tcpClient = tcpListener.AcceptTcpClient())
{
using (FileStream stream = new FileStream("fullFilePath.ext", FileMode.Create, FileAccess.ReadWrite))
{
// writing stream here
}
}
}
나는 사용하여 파일 스트림을 전송 (간체) : 그것은 잘 작동하지만 난 그 듣기 때문에 인수를 전달하는 방법을 알아낼 수 없습니다
public void SendFile(string destination, int transferPort)
{
using (TcpClient tcpClient = new TcpClient(destination, transferPort))
{
using (NetworkStream networkStream = tcpClient.GetStream())
{
// read bytes, write, and flush here
}
}
}
() 나는 그것을 전달할 수있는 '동적'인수를 가질 수 있습니다. 예를 들어, "fullFilePath.ext"는 동적이어야합니다.
도움을 주시면 감사하겠습니다.
감사합니다.
여기에서 성취하고자하는 것은 매우 명확하지 않은 것처럼 보입니다. 어떤 종류의 매개 변수를 SendFile에 전달하고 어떻게 동적으로 Listen에 영향을 줍니까? –
@JesseCarter, 생각은 "fullFilePath.ext"를 Listen() 메서드의 동적 값으로 변경할 수있게하는 것입니다. 그러나 메서드가 스레드로 시작되므로 어떻게 구현할 수 있을지 확신 할 수 없습니다. Listen()에 전달하기 위해 SendFile()의 'destination'인수가 필요합니다. – user3276006
'ThreadStart' 사용은 더 이상 사용되지 않습니다. 람다를 건네 줘. – usr