我有两个部分,一个客户端和一个服务器.我尝试从客户端向服务器发送数据(大小> 5840字节),然后服务器将数据发回.我循环了很多次,每次等待一秒钟.有时服务器应用程序崩溃,崩溃似乎非常随机的错误:
未处理的异常:System.IO.IOException:无法从传输连接读取数据:远程主机强制关闭现有连接.--->
System.Net.Sockets.SocketException:远程主机强制关闭现有连接
在System.Net.Sockets.Socket.Receive(Byte []缓冲区,Int32偏移量,Int32大小,SocketFlags socketFlags)
在System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,Int32 siz)
---内部异常堆栈跟踪结束---
在System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,Int32 siz)
at TCP_Server.Program.Main(String [] args)
客户端代码(这在循环内):
try
{
Int32 port = 13777;
using (TcpClient client = new TcpClient(ip, port))
using (NetworkStream stream = client.GetStream())
{
client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
var data = GenerateData(size);
sw.Start();
// Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length);
// Buffer to store the response bytes.
data = new Byte[size];
// Read the first batch of the TcpServer response bytes.
Int32 bytes …Run Code Online (Sandbox Code Playgroud) 我试图上传图片并使用automapper将其从HttpPostedFileBase转换为Byte [].这是我的CreateMap:
Mapper.CreateMap<HttpPostedFileBase, Byte[]>()
.ForMember(d => d, opt => opt.MapFrom(s =>
{
MemoryStream target = new MemoryStream();
s.InputStream.CopyTo(target);
return target.ToArray();
}));
Run Code Online (Sandbox Code Playgroud)
我在s上得到一个错误:带有语句体的lambda表达式无法转换为表达式树.
那么我应该如何编写我的CreateMap才能使其工作?
我有一个带有多个dropdownlistfor的Add / Edit视图,所有视图都来自同一选择列表。当我尝试填充editinng的视图时,所有dropdownlist的选择与第一个相同。有没有解决的办法?我不想使用多个选择列表,因为它们都具有相同的内容。
大多数下拉列表都是从一个列表创建的,每个项目都有一个下拉列表。这是视图的第一部分,它不是从项目列表创建的。
<div class="control-group">
@Html.LabelFor(model => model.FirstRound, new { @class = "control-label" })
<div class="controls">
@Html.DropDownListFor(model => Model.FirstRound.Id, Model.Difficulties, new { @class = "span3 combobox"})
@Html.TextBoxFor(model => Model.FirstRound.Value, new { @class = "input-xlarge span1 sec-val", @readonly = "readonly"})
@Html.ValidationMessageFor(model => model.FirstRound.Value, null, new { @class = "help-inline" })
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我循环项目列表以创建下拉列表的部分。
@{int counter = 0;}
@foreach (var item in Model.SecondRound)
{
<div class="control-group">
@Html.LabelFor(model => model.SecondRound, new { @class = "control-label" })
<div class="controls second-round">
@Html.DropDownListFor(model => model.SecondRound[counter].Id, …Run Code Online (Sandbox Code Playgroud)