在用Java编写WebSocket服务器时,我遇到了这个奇怪的错误.我把它减少到两个小的java文件,一个是服务器,另一个是客户端.客户端只需发送0x00字符串Hello然后0xFF(根据WebSocket规范).
在我的Windows机器上,服务器打印以下内容:
Listening
byte: 0
72 101 108 108 111 recieved: 'Hello'
Run Code Online (Sandbox Code Playgroud)
在我的unix框中,相同的代码打印以下内容:
Listening
byte: 0
72 101 108 108 111 -3
Run Code Online (Sandbox Code Playgroud)
获得-3而不是接收0xFF,从不打破循环并且永远不会打印它收到的内容.
代码的重要部分如下所示:
byte b = (byte)in.read();
System.out.println("byte: "+b);
StringBuilder input = new StringBuilder();
b = (byte)in.read();
while((b & 0xFF) != 0xFF){
input.append((char)b);
System.out.print(b+" ");
b = (byte)in.read();
}
inputLine = input.toString();
System.out.println("recieved: '" + inputLine+"'");
if(inputLine.equals("bye")){
break;
}
Run Code Online (Sandbox Code Playgroud)
我还将这两个文件上传到我的服务器:
我的Windows机器正在运行Windows 7,而我的Linux机器正在运行Debian
编辑:
当b是一个int时,它仍然很奇怪.我发送0xFF(255)但接收65533(不是65535或255).
我正在做一个使用JQuery和Cakephp的应用程序.
在这里我使用如下所示从我的控制器端检索值
var getformid;
$.getJSON("http://localhost/FormBuilder/index.php/forms/getFormEntry", function(json) {
getformid=json.forms[0]["id"];
alert("Form id inside "+getformid);
});//json
alert("Form id ouside "+getformid);
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,$ .getJSON内部的内部警报给我正确的值为75但外部警报显示错误为getformid未定义..为什么?我们不能使用外面的getformid $ .getJSON.请建议我.我想利用该值来保存Field ..
编辑:如果我尝试使用像这样的代码
var getformid;
$.getJSON("http://localhost/FormBuilder/index.php/forms/getFormEntry", myCallback);
function myCallback (json) {
getformid = json.forms[0]["id"];
// You can work with the response here
}
Run Code Online (Sandbox Code Playgroud)
我收到错误,像myCallback没有定义.WHy所以?我也应该在函数myCallback()之外使用getformid值
我有一个(约200-300)2d点的列表.我知道需要找到包含所有这些的多边形.多边形必须是凸的,并且它应该尽可能复杂(即不是矩形边界框).它应该在尽可能低的时间内找到它,但对内存没有限制.
您可以使用伪代码或任何要使用的语言进行回答.
我想检查是否已使用NSubstitute调用匿名函数.类I中的方法有一个Func<>参数,我想确保调用(或不调用)此参数.我尝试了以下,但它似乎不起作用:
var spy = Substitute.For<Func<string, int>>();
MyClass.DoSomething(spy);
spy.Invoke(Arg.Any<string>()).Received();
Run Code Online (Sandbox Code Playgroud)
然而,这引发了一个例外:
NSubstitute.Exceptions.NullSubstituteReferenceException : NSubstitute extension methods like .Received can only be called on objects created using Substitute.For<T>() and related methods.
Run Code Online (Sandbox Code Playgroud) ConfigurationSection我在网上找到的例子(例如)都有如下代码:
public class ConnectionSection : ConfigurationSection
{
[ConfigurationProperty("Servers")]
public ServerAppearanceCollection ServerElement
{
get { return ((ServerAppearanceCollection)(base["Servers"])); }
set { base["Servers"] = value; }
}
}
Run Code Online (Sandbox Code Playgroud)
为什么使用方括号从基数访问值"Servers"?是从xml创建此对象时使用的setter,还是用于覆盖xml文件中的值的setter?如果是这样,为什么在此属性上设置属性?
假设我想将标识服务器的对象放入stl中set.然后我必须确保我也operator<为这些对象实现,否则我会遇到编译器错误:
struct ServerID
{
std::string name; // name of the server
int port;
};
std::set<ServerID> servers; // compiler error, no operator< defined
Run Code Online (Sandbox Code Playgroud)
这只是我想要使对象具有可比性的常见问题的一个例子.
我目前的解决方案通常是这样的:
bool operator< (const ServerID & lhs, const ServerID & rhs)
{
if (lhs.name != rhs.name)
{
return lhs.name < rhs.name;
}
else
{
return lhs.port < rhs.port;
}
}
Run Code Online (Sandbox Code Playgroud)
这只是我发现自己的解决方案.但我怀疑这个问题也可能在计算机科学中得到认可.所以,如果我很幸运,有一个更好的解决方案.任何人都可以向我暗示吗?
让我说我有一个控制器动作不能异步(由于各种原因),但我有一个服务(通过几种方法)调用休息服务使用HttpClient.使用异步客户端并使用.Wait或是否有任何好处.Result?或者使用同步方法的性能会降低吗?
所以要么:
//MyController.cs
public ActionResult GetSomething(int id)
{
//lots of stuff here
var processedResponse = _myService.Get(id);
//lots more stuff here
return new ContentResult(result);
}
//MyService.cs
public ProcessedResponse Get(int id)
{
var client = new HttpClient();
var result = client.Get(_url+id);
return Process(result);
}
Run Code Online (Sandbox Code Playgroud)
要么:
//MyController.cs
public ActionResult GetSomething(int id)
{
//lots of stuff here
var processedResponse = _myService.GetAsync(id).Result;
//or, .Wait, or Task.Run(...), or something similar
//lots more stuff here
return new ContentResult(result);
}
//MyService.cs
public …Run Code Online (Sandbox Code Playgroud) 我有一个带有专辑的mysql表.每张专辑可以是顶级专辑,也可以是其他专辑的儿童专辑.每张专辑都有一个foldername,它是其图片所在文件夹的名称.每张专辑还有一个名为parent的字段,即父母专辑的id.所以,如果我有一个像这样的图像的路径:
root/album1/album2/image1.jpg
Run Code Online (Sandbox Code Playgroud)
那么数据库中的专辑表将如下所示:
id parent foldername
1 NULL root
2 1 album1
3 2 album2
Run Code Online (Sandbox Code Playgroud)
那么问题是,如何只使用mysql从此表中获取之前打印的路径?
我有一个表格,可以按等级排序.我想获得前10个条目(这很简单SELECT * FROM table ORDER BY rank DESC,但是我希望这些条目按降序排列,因此排名最低的条目最终会在顶部.我该怎么做?
我需要比较两个数组:
var objects = [{name: 'a', is: false}, {name: 'b', is: false}, {name: 'c', is: false}];
var strings = ['a', 'b'];
Run Code Online (Sandbox Code Playgroud)
如果对象中的对象等于字符串中的字符串之一,则将字段更改is为 true,但我不知道该怎么做
我在sqlite3中获取准备好的语句时遇到了麻烦.我正在使用Perl和Perl DBD框架.以下是我使用的代码:
#This is a function I have defined
sub query($@){
my $st = $db->prepare(shift);
$st->execute(@_);
}
#And it is used like so
query("UPDATE rooms SET name = ?, SET capacity = ? WHERE id = ?",
$name, $capacity, $id);
Run Code Online (Sandbox Code Playgroud)
当我尝试时,我收到以下错误:
DBD::SQLite::db prepare failed: near "SET": syntax error(1) at dbdimp.c line 271 at database.pm line 80.
为什么我会收到这个错误?如果我在不使用准备好的语句的情 我的应用程序中的每个其他预准备语句都有效,但UPDATE查询除外.
c# ×3
algorithm ×2
mysql ×2
.net ×1
arrays ×1
asp.net ×1
async-await ×1
asynchronous ×1
c++ ×1
cakephp ×1
concat ×1
directory ×1
func ×1
java ×1
javascript ×1
jquery ×1
linux ×1
math ×1
nsubstitute ×1
perl ×1
polygon ×1
sockets ×1
sql-order-by ×1
sqlite ×1
string ×1
syntax-error ×1
tree ×1