다음 Console.Write 방법은 완벽하게 작동, 및 텍스트 출력이 화면에 표시되어 있지만내가 텍스트 파일에 텍스트를 쓰기를 시도하고
byte[] b = new byte[100];
int k = s.Receive(b);
Console.WriteLine("Recieved...");
for (int i = 0; i < k; i++)
{
Console.Write(Convert.ToChar(b[i]));
//TextWriter tw = new StreamWriter("output.txt");
//tw.WriteLine(Convert.ToChar(b[i]));
}
하지만, TextWriter 메서드를 사용하면 응용 프로그램이 100 개의 오류를 생성하고 (계속) 지정된 출력 파일에 아무 것도 출력하지 않습니다.
"Console.Write (Convert.ToChar (b [ 나는]));" 텍스트 파일에? 다음은
가 오류의 예입니다 : 서버가 포트 8111에서 실행... 지역 종점 입니다 : 172.16.0.37 : 8111가 연결 ..... 연결 대기 중 받아 들인 내용 172.16.0.37:59307 수신 ... // 오류 ..... 에서 System.IO .__ Error.WinIOError (Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init (String path, FileMode 모드, FileAccess 액세스, Int32 권한, 부울 useRights, FileShare 공유, Int32 bufferSize, FileOptions 옵션, SECURITY_ATTRIBUTES secAttrs, St ( 경로, FileMode 모드, FileAccess 액세스, FileShare 공유, Int32 bufferSize, FileOptions 옵션)에서 msg.BufferProxy.BufferFile (String path, 부울 추가)에서 의 Integer.Main()에있는 System.IO.StreamWriter..ctor (문자열 경로)의 System.IO.StreamWriter..ctor (문자열 경로, 부울 추가, 인코딩 인코딩, Int32 버퍼 크기) : \ Users \ Limited \ Desktop \ IntegClient \ IntegServer \ IntegServer \ Program.cs : 38 오류 ..... System.Net.Sockets.Socket.DoBind (끝점 endPointSnapshot, SocketAddress socketAddress)에서 System.Net .Sockets.Socket.Bind (EndPoint localEP)에 있습니다. System.Net.Sockets.TcpListener.Start (Int32 백 로그) 의 Integer.Main()에서 System.Net.Sockets.TcpListener.Start() C : \ Users \ Limited \ Desktop \ IntegClient \ IntegServer \ IntegServer \ Program.cs : 라인 21 오류 ..... 시스템에서 System.Net.Sockets.Socket.Bind에서 System.Net.Sockets.Socket.DoBind (를 EndPoint endPointSnapshot, SocketAddress를 않은 SocketAddress()를 EndPoint localEP)에서. Integers.Main()의 에있는 System.Net.Sockets.TcpListener.Start() C : \ Users \ Limited \ Desktop \ IntegClient \ IntegServer \ IntegServer \ Program.cs의 Net.Sockets.TcpListener.Start (Int32 백 로그) : 줄 21 오류 ..... System.Net.Sockets.Socket.DoBind (끝점 endPointSnapshot, SocketAddress socketAddress) System.Net.Sockets.TcpListener.Start에서 System.Net.Sockets.TcpListener.Start (INT32 잔고)에 System.Net.Sockets.Socket.Bind (localEP를 EndPoint)()에서
전체 코드는 다음과 같습니다.
try
{
IPAddress ipAd = IPAddress.Parse("172.16.0.37"); //use local m/c IP address, and use the same in the client
/* Initializes the Listener */
TcpListener myList = new TcpListener(ipAd, 8111);
/* Start Listeneting at the specified port */
myList.Start();
Console.WriteLine("The server is running at port 8111...");
Console.WriteLine("The local End point is :" + myList.LocalEndpoint);
Console.WriteLine("Waiting for a connection.....");
Socket s = myList.AcceptSocket();
Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);
byte[] b = new byte[100];
int k = s.Receive(b);
Console.WriteLine("Recieved...");
using (var txt = File.OpenWrite("output.txt"))
{
for (int i = 0; i < k; i++)
{
Console.Write(Convert.ToChar(b[i]));
txt.WriteLine(Convert.ToChar(b[i]));
}
}
ASCIIEncoding asen = new ASCIIEncoding();
s.Send(asen.GetBytes("The string was recieved by the server."));
Console.WriteLine("\nSent Acknowledgement to Client");
/* clean up */
s.Close();
myList.Stop();
}
catch (Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
}
// Loop the process
loop();
}
무엇을 오류? (어쩌면 그들 중 일부만을 ...) – David
'TextWriter'를 사용할 때 얻는 오류는 무엇입니까? –
루프에 새 작성자가 있습니까? 그것은 문제를 요구하고있다 – Rob