Skip to main content
deleted 2 characters in body
Source Link
user6766561
user6766561

I'm making a server - client program using TcpClient and server.

To send from the server I use:

static void send(string data) { sw.WriteLine(data + Environment.NewLine); } 

And when the client connects I'm sending some text:

client = listener.AcceptTcpClient(); sr = new StreamReader(client.GetStream()); sw = new StreamWriter(client.GetStream()); string line; try { send("Hello world"); } //More code 

And to read from client:

string data; data = sr.ReadLine(); if(data != string.Empty || data != null) { MessageBox.Show(data); } 

I tried putting inside while(true) and it froze, I tried putting inside a timer tick loop and it crashedfroze...

How do I fix this?

P.S: The client and the server are 2 different projects.

I'm making a server - client program using TcpClient and server.

To send from the server I use:

static void send(string data) { sw.WriteLine(data + Environment.NewLine); } 

And when the client connects I'm sending some text:

client = listener.AcceptTcpClient(); sr = new StreamReader(client.GetStream()); sw = new StreamWriter(client.GetStream()); string line; try { send("Hello world"); } //More code 

And to read from client:

string data; data = sr.ReadLine(); if(data != string.Empty || data != null) { MessageBox.Show(data); } 

I tried putting inside while(true) and it froze, I tried putting inside a timer tick loop and it crashed...

How do I fix this?

P.S: The client and the server are 2 different projects.

I'm making a server - client program using TcpClient and server.

To send from the server I use:

static void send(string data) { sw.WriteLine(data + Environment.NewLine); } 

And when the client connects I'm sending some text:

client = listener.AcceptTcpClient(); sr = new StreamReader(client.GetStream()); sw = new StreamWriter(client.GetStream()); string line; try { send("Hello world"); } //More code 

And to read from client:

string data; data = sr.ReadLine(); if(data != string.Empty || data != null) { MessageBox.Show(data); } 

I tried putting inside while(true) and it froze, I tried putting inside a timer tick loop and it froze...

How do I fix this?

P.S: The client and the server are 2 different projects.

improved formatting
Source Link
HasaniH
  • 8.4k
  • 6
  • 47
  • 62

I'm making a server - client program using TcpClientTcpClient and server.

To send from the server I use:

static void send(string data) { sw.WriteLine(data + Environment.NewLine); } 

And when the client connects I'm sending some text:

client = listener.AcceptTcpClient(); sr = new StreamReader(client.GetStream()); sw = new StreamWriter(client.GetStream()); string line; try { send("Hello world"); } //More code 

And to read from client: string data; data = sr.ReadLine();

string data; data = sr.ReadLine(); if(data != string.Empty || data != null) { MessageBox.Show(data); } 

I tried putting inside while(true) and it froze, I tried putting inside a timer tick loop and it crashed...

How do I fix this?

P.S: The client and the server are 2 different projects.

I'm making a server - client program using TcpClient and server.

To send from the server I use:

static void send(string data) { sw.WriteLine(data + Environment.NewLine); } 

And when the client connects I'm sending some text:

client = listener.AcceptTcpClient(); sr = new StreamReader(client.GetStream()); sw = new StreamWriter(client.GetStream()); string line; try { send("Hello world"); } //More code 

And to read from client: string data; data = sr.ReadLine();

if(data != string.Empty || data != null) { MessageBox.Show(data); } 

I tried putting inside while(true) and it froze, I tried putting inside a timer tick loop and it crashed...

How do I fix this?

P.S: The client and the server are 2 different projects.

I'm making a server - client program using TcpClient and server.

To send from the server I use:

static void send(string data) { sw.WriteLine(data + Environment.NewLine); } 

And when the client connects I'm sending some text:

client = listener.AcceptTcpClient(); sr = new StreamReader(client.GetStream()); sw = new StreamWriter(client.GetStream()); string line; try { send("Hello world"); } //More code 

And to read from client:

string data; data = sr.ReadLine(); if(data != string.Empty || data != null) { MessageBox.Show(data); } 

I tried putting inside while(true) and it froze, I tried putting inside a timer tick loop and it crashed...

How do I fix this?

P.S: The client and the server are 2 different projects.

Source Link
user6766561
user6766561

C# Reading stream from TcpClient

I'm making a server - client program using TcpClient and server.

To send from the server I use:

static void send(string data) { sw.WriteLine(data + Environment.NewLine); } 

And when the client connects I'm sending some text:

client = listener.AcceptTcpClient(); sr = new StreamReader(client.GetStream()); sw = new StreamWriter(client.GetStream()); string line; try { send("Hello world"); } //More code 

And to read from client: string data; data = sr.ReadLine();

if(data != string.Empty || data != null) { MessageBox.Show(data); } 

I tried putting inside while(true) and it froze, I tried putting inside a timer tick loop and it crashed...

How do I fix this?

P.S: The client and the server are 2 different projects.