我的问题是,当我通过LOCAL LAN网络传输连续的数据流时,有时随机字节会在此过程中丢失.
现在,代码被设置为在LAN上传输大约1027个字节左右~40次,有时(非常罕见)一个或多个字节丢失.
令我感到困惑的是,实际字节不会"丢失",无论原始数据如何,它都只是设置为0.(我顺便使用TCP)
这是发送代码:
public void Send(byte[] data)
{
if (!server)
{
if (CheckConnection(serv))
{
serv.Send(BitConverter.GetBytes(data.Length));
serv.Receive(new byte[1]);
serv.Send(data);
serv.Receive(new byte[1]);
}
}
}
Run Code Online (Sandbox Code Playgroud)
和接收代码:
public byte[] Receive()
{
if (!server)
{
if (CheckConnection(serv))
{
byte[] TMP = new byte[4];
serv.Receive(TMP);
TMP = new byte[BitConverter.ToInt32(TMP, 0)];
serv.Send(new byte[1]);
serv.Receive(TMP);
serv.Send(new byte[1]);
return TMP;
}
else return null;
}
else return null;
}
Run Code Online (Sandbox Code Playgroud)
发送和接收空字节只是为了使系统保持同步排序.我个人认为问题出在系统的接收方.虽然没能证明那架喷气机.
我有以下简化表:
tblOrders
orderID date
---------------------
1 2013-10-04
2 2013-10-05
3 2013-10-06
Run Code Online (Sandbox Code Playgroud)
tblOrderLines
lineID orderID ProductCategory
--------------------------------------
1 1 10
2 1 3
3 1 10
4 2 3
5 3 3
6 3 10
7 3 10
Run Code Online (Sandbox Code Playgroud)
我想从tblOrders中选择记录,如果任何订单行有ProductCategory = 10.因此,如果特定订单的所有行都没有ProductCategory = 10,那么不要返回该订单.
我该怎么办?
我有2个构造函数,其中有一个基本调用;
public MyApplication(myEntities context)
:base(context)
{
_1stApp = new 1stApplication(this._context);
_2ndApp = new 2ndApplication(this._context);
// etc...
}
public MyApplication()
:base()
{
_1stApp = new 1stApplication(this._context);
_2ndApp = new 2ndApplication(this._context);
// etc...
}
Run Code Online (Sandbox Code Playgroud)
以及基础构造函数
public BaseApplication()
{
_context= new myEntities ();
}
public BaseApplication(myEntities context)
{
if (context==null)
_context = context;
else
_context= new myEntities ();
}
Run Code Online (Sandbox Code Playgroud)
在MyApplication构造函数中,我想要传递由另一个应用程序创建的上下文,或者我想创建一个新的上下文.在任何一种情况下,我都希望与MyApplication实例化的所有其他应用程序类(1stApp,2ndApp等)共享相同的上下文.
我不想在两个地方保持相同的代码.
有一个非常简单的问题,我之前没有遇到过.我在做项目之前使用了类似的布局.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class q1
{
public static void main (String Args [])
{
q1Window showMe = new q1Window();
}
}
class q1Window
{
q1Window()
{
JFrame window = new JFrame("Tutorial 1");
window.setSize(600,600);
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint (Graphics back)
{
back.setColor(Color.black);
back.fillRect(30,30,100,200);
}
}
Run Code Online (Sandbox Code Playgroud)
现在我似乎无法打印任何JFrame显示的东西.
在超级搜索perl中转换编码文件的方法之后,我总是问自己这是做什么的最佳方法.
我的问题很简单:我有很多不同编码的文件(UTF-8,ISO-8859-1,windows-1252 ......),我想在ISO-8859-1中转换所有这些文件.
我是来自Java的.net新手.我已经返回一行代码ArrayList,但我知道所有元素都是MyType.我怎样才能轻易地模仿ArrayList?重申一下,我有
ArrayList arr = getArrayList();
Run Code Online (Sandbox Code Playgroud)
而且我要
ArrayList<MyType> arr = getArrayList();
Run Code Online (Sandbox Code Playgroud)
我试过ArrayList<MyType> arr = getArrayList() as ArrayList<MyType>但它说Class 'System.Collections.ArrayList' does not have type parameters
我有一个足够简单的类,用于将文本记录到.txt文件中我遇到的问题是,如果文本文件不存在,我将在代码中显示的点处获得异常.程序崩溃后,文本文件出现在文件夹中.如果我在log.txt文件存在的情况下运行该程序,它可以完美地运行.
代码:
class logger
{
public string source;
//public logger()
//{
//}
public logger(string source)
{
CheckExists(source);
this.source = source + "log.txt";
}
private void CheckExists(string source)
{
if (!File.Exists(source + "log.txt"))
{
File.Create(source + "log.txt");
}
}
public void WriteToLog(string output)
{
try
{
using (StreamWriter sw = File.AppendText(this.source))
{
sw.WriteLine(output);
sw.Close();
}
}
catch (Exception e)
{
//point at which the code breaks;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试运行我的 WCF 服务,但出于某种原因我总是遇到以下错误:
'' 处的端点没有与 None MessageVersion 的绑定。“System.ServiceModel.Description.WebHttpBehavior”仅适用于 WebHttpBinding 或类似的绑定。
网络配置
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="Default" name="AF_ES.SG">
<endpoint address="rest" behaviorConfiguration="webBehavior" binding="webHttpBinding" contract="AF_ES.IServices.ISG" />
<endpoint address="soap" behaviorConfiguration="soapBehavior" binding="basicHttpBinding" contract="AF_ES.IServices.ISG" />
</service>
</services>
<behaviors> …Run Code Online (Sandbox Code Playgroud) 我想计算数组中特定值的出现次数,数组如下.
my @array = (-1.001, -7.032, -5.013, 8.412, -1.500, 3.412)
Run Code Online (Sandbox Code Playgroud)
预期结果对于零计数值= 4
对于负5以下的值= 2
如何使用Perl,Any Idea获取它?
我项目的结构:
class Attachment { ... }
class Photo : Attachment { ... }
class Document : Attachment { ... }
class Page
{
public List<Attachment> attachments;
...
}
Run Code Online (Sandbox Code Playgroud)
我收到服务器的页面:
List<Page> pages = ...load pages from server;
Run Code Online (Sandbox Code Playgroud)
我需要从这个列表页面中获取附件中只有类型为Photo的对象.
我该怎么做?