I am trying to connect to a socket and then Read a NetworkStream.
My code is below:
NetworkStream myNetworkStream;
Socket socket;
socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IPv4);
socket.Connect(IPAddress.Parse("8.8.8.8"), 8888);
myNetworkStream = new NetworkStream(socket);
byte[] buffer = new byte[1024];
int offset = 0;
int count = 1024;
myNetworkStream.Read(buffer, offset, count);
When I try to debug the above I get the following error:
The operation is not allowed on non-stream oriented sockets.
What am I doing wrong?
Thanks
You need to use
SocketType.Streamin lieu ofSocketType.Raw.