TcpClient
및 서버를 사용하여 서버 클라이언트 프로그램을 만들고 있습니다. C# TcpClient에서 스트림 읽기
client = listener.AcceptTcpClient();
sr = new StreamReader(client.GetStream());
sw = new StreamWriter(client.GetStream());
string line;
try
{
send("Hello world");
} //More code
그리고 클라이언트에서 읽을 수 :
string data;
data = sr.ReadLine();
if(data != string.Empty || data != null)
{
MessageBox.Show(data);
}
static void send(string data)
{
sw.WriteLine(data + Environment.NewLine);
}
그리고 클라이언트는 내가 텍스트를 보내고있다 연결할 때
안에 넣어려고했는데 (사실) 타이머 얼룩 루프 안에 넣어 봤는데 얼어 버렸어요.
어떻게 해결할 수 있습니까?
P .: 클라이언트와 서버는 서로 다른 두 개의 프로젝트입니다.
try
{
listen = new TcpListener(myAddress, port);
listen.Start();
Byte[] bytes;
while (true)
{
TcpClient client = listen.AcceptTcpClient();
NetworkStream ns = client.GetStream();
if(client.ReceiveBufferSize > 0){
bytes = new byte[client.ReceiveBufferSize];
ns.Read(bytes, 0, client.ReceiveBufferSize);
string msg = Encoding.ASCII.GetString(bytes); //the message incoming
MessageBox.Show(msg);
}
}
}
catch(Exception e)
{
//e
}
그런 다음 백그라운드 스레드로이 코드를 가지고 : 나는 당신이 필요로하는 것을 이해 바랍니다
Thread thread = new Thread(the functions name);
thread.IsBackground = true;
thread.Start();
무엇이 고정되어 있습니까? 어떤 라인이 충돌을 일으키는 예외를 던집니까? – SpaceghostAli
Dosen't 예외를 throw, 프로그램은 그냥 –
당신은 당신이 그것을 "타이머 틱 루프에 넣고 추락했다"고 말했다. 첫 번째 질문은 디버거에서 코드를 단계별로 진행하면 어떤 줄이 멈추는가? – SpaceghostAli