我正在编写支持多人游戏的Android视频游戏.有一个专用的服务器运行,当通过打开套接字点击多人游戏按钮时,机器人连接到这个服务器(这很好).服务器基本上只是作为配对系统.
当客户端托管游戏时,服务器会将该客户端添加到主机列表中.其他客户端可以选择查看此列表,然后连接到该主机.这就是问题所在.服务器应该跟踪主机的ip /端口,然后其他客户端应该使用此信息与主机打开套接字然后游戏启动.我正在尝试让主机将自己的IP地址发送到服务器以供其他客户端稍后使用.
到目前为止,我尝试了很多方法.一个是:
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress().toString();
}
}
}
} catch (SocketException ex) {
}
Run Code Online (Sandbox Code Playgroud)
这将返回10.0.2.15,这显然对其他客户端无用.
我试过的另一种方法是:
String hostName = InetAddress.getLocalHost().getHostName();
InetAddress addrs[] = InetAddress.getAllByName(hostName);
for (InetAddress addr: addrs) {
System.out.println ("addr.getHostAddress() = " + addr.getHostAddress());
System.out.println ("addr.getHostName() = " + addr.getHostName());
System.out.println ("addr.isAnyLocalAddress() = " + addr.isAnyLocalAddress());
System.out.println ("addr.isLinkLocalAddress() = " + …Run Code Online (Sandbox Code Playgroud) 我们可以在非UI线程中更新WPF控件的数据上下文吗?
假设我们有一个Label有MyClass作为数据上下文,并绑定Content到MyProperty:
<Label Name="label" Content="{Binding MyProperty}" />,
其中,MyClass无非是:
public class MyClass : INotifyPropertyChanged
{
int _myField;
public int MyProperty
{
get
{
return _myField;
}
set
{
_myField = value;
PropertyChanged(this, new PropertyChangedEventArgs("MyProperty"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
Run Code Online (Sandbox Code Playgroud)
在非UI线程中,我们可以myClass.MyProperty = "updated"更新标签的内容,但我们不能label.Content = "updated"直接做.那是对的吗?
我自己的答案:
这是我发现的:
ObserverableCollection绑定到控件的项添加项或从中删除项.但有一个解决方法:http://geekswithblogs.net/NewThingsILearned/archive/2008/01/16/have-worker-thread-update-observablecollection-that-is-bound-to-a.aspx所以我在最后一小时一直在浏览互联网,阅读并寻找这个简单问题的最终答案.
MySQL中的默认JOIN是什么?
SELECT * FROM t1 JOIN t2
Run Code Online (Sandbox Code Playgroud)
这是一样的吗?
SELECT * FROM t1, t2
OR
SELECT * FROM t1 INNER JOIN t2
Run Code Online (Sandbox Code Playgroud)
还有一个相关的问题,当你使用"WHERE"子句时,它是否与JOIN或INNER JOIN相同?
现在我认为独立的JOIN与使用逗号和WHERE子句相同.
我有搜索存储过程,这是我的性能瓶颈.
为了控制发生的事情,我添加了所有参数的记录以及SP中的执行时间.
我注意到,当我叫SP从Microsoft SQL Server Management Studio中执行时间为1.3-1.6秒,但是当我从C#调用它,它需要6-8 secods(!!!)
Parameters | Time (ms)
"tb *"TreeType:259Parents:212fL:13;14fV:0;lcid:2057min:0max:10sort:-1 | 6406
"tb *"TreeType:259Parents:212fL:13;14fV:0;lcid:2057min:0max:10sort:-1 | 1346
Run Code Online (Sandbox Code Playgroud)
使用LINQ调用SP.登录设置相同.SP使用全文搜索
什么可能导致这个?
嘿伙计们我遇到了rails root routs的一些问题.由于某种原因,我无法获得根URL(localhost:3000 /)来路由到适当的地方.
我已经构建了一个全新的应用程序,并使用脚手架来生成"问题"模型.我可以确认存在"索引"操作(默认情况下来自scaffold)
这是我的代码:
Fbauth::Application.routes.draw do
resources :questions
root :to => 'questions#index'
end
Run Code Online (Sandbox Code Playgroud)
耙路输出:
(in /home/jsfour/rails3_apps/fbauth)
questions GET /questions(.:format) {:action=>"index", :controller=>"questions"}
POST /questions(.:format) {:action=>"create", :controller=>"questions"}
new_question GET /questions/new(.:format) {:action=>"new", :controller=>"questions"}
edit_question GET /questions/:id/edit(.:format) {:action=>"edit", :controller=>"questions"}
question GET /questions/:id(.:format) {:action=>"show", :controller=>"questions"}
PUT /questions/:id(.:format) {:action=>"update", :controller=>"questions"}
DELETE /questions/:id(.:format) {:action=>"destroy", :controller=>"questions"}
root /(.:format) {:controller=>"questions", :action=>"index"}
Run Code Online (Sandbox Code Playgroud)
这里有什么问题?为什么localhost:3000 /给我"欢迎使用rails"的消息?
说我有一个清单
1M 3M 5D 3Y 9Y
我希望使用vim快速将此列表转换为"1M","3M","5D","3Y","9Y" - 到目前为止我手动执行此操作.谢谢
我在xcode中创建了一个核心数据模式(3.2.5,如果它很重要),所以我有.xcdatamodel文件,其中包含正确的实体和关系.
现在 - 如何从代码中插入数据,编辑数据和/或删除数据?
就像phpMyAdmin用于MySql一样.
谢谢.
填写表单的textarea时,按下回车键时的默认行为是移动到下一行.我如何更改表单的行为,以便即使用户在textarea中,它也会在用户点击输入时提交?
我使用Firebug来检查Stack Overflow的注释textarea(有这种行为),但是看不到任何实现这种效果的JavaScript.有没有办法在不使用JavaScript的情况下改变textarea的行为?
文件说,航点限制是8分.但我必须绘制一条超过8个航点的线.怎么做?
android ×1
c# ×1
core-data ×1
directions ×1
forms ×1
google-maps ×1
html ×1
ios ×1
java ×1
join ×1
linq ×1
mysql ×1
networking ×1
objective-c ×1
performance ×1
php ×1
select ×1
t-sql ×1
vi ×1
vim ×1
wpf ×1
xcode ×1