开发者

Convert stream to object?

Newbie question for you. I have the following code. I get an error because a object has to be passed to ClientRequest. But am unsure how pass the stream as a object.

TcpClient _client = _listener.AcceptTcpClient();

NetworkStream _开发者_Python百科clientStream = _client.GetStream(); ThreadPool.QueueUserWorkItem(ClientRequest, _clientStream);

Thanks


There's nothing wrong with that code as long as ClientRequest is declared like so:

public void ClientRequest(Object state) {
 ...
}


The problem is probably not that you can't pass the stream as an object -- Everything in .net is an object, so casting to object (which is a "widening" conversion, and thus doesn't need to be specified) shouldn't be an issue.

My guess is your ClientRequest is expecting to be passed a NetworkStream or something, which it's not going to get -- it's going to get an object, which you'll then need to cast to a NetworkStream in order to use it properly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜