本文整理汇总了C#中NetworkStream.ReadInt32方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkStream.ReadInt32方法的具体用法?C# NetworkStream.ReadInt32怎么用?C# NetworkStream.ReadInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkStream
的用法示例。
在下文中一共展示了NetworkStream.ReadInt32方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ListenForConnection
private static void ListenForConnection()
{
try {
for (; ; ) {
var socket = _listenerSocket.Accept();
var stream = new NetworkStream(socket, ownsSocket: true);
try {
socket.Blocking = true;
string debugId = stream.ReadString();
var result = (ConnErrorMessages)stream.ReadInt32();
lock (_targets) {
Guid debugGuid;
WeakReference weakProcess;
JProcess targetProcess;
if (Guid.TryParse(debugId, out debugGuid) &&
_targets.TryGetValue(debugGuid, out weakProcess) &&
(targetProcess = weakProcess.Target as JProcess) != null) {
if (result == ConnErrorMessages.None) {
targetProcess.Connected(socket, stream);
} else {
var outWin = (IVsOutputWindow)Package.GetGlobalService(typeof(IVsOutputWindow));
IVsOutputWindowPane pane;
if (outWin != null && ErrorHandler.Succeeded(outWin.GetPane(VSConstants.GUID_OutWindowDebugPane, out pane))) {
pane.Activate();
string moduleName;
try {
moduleName = Process.GetProcessById(targetProcess.Id).MainModule.ModuleName;
} catch {
// either the process is no longer around, or it's a 64-bit process
// and we can't get the EXE name.
moduleName = null;
}
if (moduleName != null) {
pane.OutputString(String.Format("Failed to connect to process {0} ({1}): {2}",
targetProcess.Id,
moduleName,
result.GetErrorMessage())
);
} else {
pane.OutputString(String.Format("Failed to connect to process {0}: {1}",
targetProcess.Id,
result.GetErrorMessage())
);
}
}
targetProcess.Unregister();
}
} else {
Debug.WriteLine("Unknown debug target: {0}", debugId);
stream.Close();
}
}
} catch (IOException) {
} catch (SocketException) {
}
}
} catch (SocketException) {
} finally {
_listenerSocket.Close();
_listenerSocket = null;
}
}
示例2: AcceptConnection
private static void AcceptConnection(IAsyncResult iar) {
Socket socket;
var socketSource = ((Socket)iar.AsyncState);
try {
socket = socketSource.EndAccept(iar);
} catch (SocketException ex) {
Debug.WriteLine("DebugConnectionListener socket failed");
Debug.WriteLine(ex);
return;
} catch (ObjectDisposedException) {
Debug.WriteLine("DebugConnectionListener socket closed");
return;
}
var stream = new NetworkStream(socket, ownsSocket: true);
try {
socket.Blocking = true;
string debugId = stream.ReadString();
var result = (ConnErrorMessages)stream.ReadInt32();
lock (_targets) {
Guid debugGuid;
WeakReference weakProcess;
PythonProcess targetProcess;
if (Guid.TryParse(debugId, out debugGuid) &&
_targets.TryGetValue(debugGuid, out weakProcess) &&
(targetProcess = weakProcess.Target as PythonProcess) != null) {
if (result == ConnErrorMessages.None) {
targetProcess.Connect(stream);
stream = null;
socket = null;
} else {
WriteErrorToOutputWindow(result, targetProcess);
targetProcess.Unregister();
}
} else {
Debug.WriteLine("Unknown debug target: {0}", debugId);
}
}
} catch (IOException) {
} catch (SocketException) {
} finally {
if (stream != null) {
stream.Dispose();
}
if (socket != null) {
socket.Dispose();
}
}
socketSource.BeginAccept(AcceptConnection, socketSource);
}