G
Guest
Hi
I listen on a port, when data is received I raise an event
(OnMessageReceived) in the while loop as follows:
private void WaitForConnection() {
TcpListener listener = new TcpListener(IPAddress.Any, 1234);
Stream data = null;
Socket socket = null;
listener.Start();
socket = listener.AcceptSocket();
try {
while(true) {
byte[] buffer = new byte[this.m_buffer];
int byteSize = 0;
byteSize = socket.Receive(buffer);
data = new MemoryStream(buffer, 0, byteSize);
OnMessageReceived(this, new MessageReceivedEventArgs(data));
}
}
catch {
throw;
}
finally {
if(data != null) data.Close();
if(socket != null) socket.Close();
}
}
The delegate assigned to the OnMessageReceived doesn't receive the event
notification, no exception is thrown in the WaitForConnection method. Does
anyone have any suggestions as to why?
Craig
I listen on a port, when data is received I raise an event
(OnMessageReceived) in the while loop as follows:
private void WaitForConnection() {
TcpListener listener = new TcpListener(IPAddress.Any, 1234);
Stream data = null;
Socket socket = null;
listener.Start();
socket = listener.AcceptSocket();
try {
while(true) {
byte[] buffer = new byte[this.m_buffer];
int byteSize = 0;
byteSize = socket.Receive(buffer);
data = new MemoryStream(buffer, 0, byteSize);
OnMessageReceived(this, new MessageReceivedEventArgs(data));
}
}
catch {
throw;
}
finally {
if(data != null) data.Close();
if(socket != null) socket.Close();
}
}
The delegate assigned to the OnMessageReceived doesn't receive the event
notification, no exception is thrown in the WaitForConnection method. Does
anyone have any suggestions as to why?
Craig