在android中,有两个类LocalServerSocket和LocalSocket.我认为它们类似于unix socket中的AF_LOCAL(我不确定它是否正确).
我的问题是:是否可以在Java中创建LocalServerSocket并使用普通的unix套接字客户端在本机或其他进程中连接到它?
如果有可能,我应该在本机中设置"sockaddr_un.sun_path"是什么?
我编写了一个示例项目来测试它,我尝试将.sun_path设置为与LocalServerSocket中使用的字符串名称相同,但是它失败了,本机无法连接到Java LocalServerSocket.
我的Java代码:
package test.socket;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.net.LocalServerSocket;
import android.net.LocalSocket;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class TestSocketActivity extends Activity {
public static String SOCKET_ADDRESS = "my.local.socket.address";
public String TAG = "Socket_Test";
static{System.loadLibrary("testSocket");}
private native void clientSocketThreadNative();
private native void setStopThreadNative();
localServerSocket mLocalServerSocket;
localClientSocket mLocalClientSocket;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mLocalServerSocket = new localServerSocket(); …Run Code Online (Sandbox Code Playgroud) 好的,我还是Java的新手.我们已经获得了一个帮助来创建一个游戏,您必须猜测计算机生成的随机整数.问题是我们的讲师坚持要求我们使用:
double randNumber = Math.random();
Run Code Online (Sandbox Code Playgroud)
然后将其转换为接受1 - 100(包括1和100)的随机整数.我有点不知所措.到目前为止我所拥有的是:
//Create random number 0 - 99
double randNumber = Math.random();
d = randNumber * 100;
//Type cast double to int
int randomInt = (int)d;
Run Code Online (Sandbox Code Playgroud)
然而,随机双重的延迟问题的随机性是0是可能性而100不是.我想改变它,以便0不是可能的答案,100是.救命?
嗨,我想提出一个小的webapp,但我遇到了错误.以下是我的代码
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("SomeURL"); // Using a URL local to my machine
// after setting nameValuePair and setting it on httppost
httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
// This is where I am getting the above mentioned exception
HttpResponse response = httpclient.execute(httppost);
Run Code Online (Sandbox Code Playgroud)
我使用的是httpclient-4.0-beta2.jar和httpcore-4.0.1.jar.看起来BasicHttpContext与我的应用程序中的其他一些罐子发生了冲突,但我无法弄明白.任何线索将不胜感激.
我有2个文件A.cpp和B.cpp看起来像
A.cpp
----------
class w
{
public:
w();
};
B.cpp
-----------
class w
{
public:
w();
};
Run Code Online (Sandbox Code Playgroud)
现在我读到了某个地方(http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=%2Fcom.ibm.xlcpp8a.doc%2Flanguage%2Fref%2Fcplr082.htm)连锁.因此,虽然构建我期待多重定义错误,但相反它有点像魅力.但是当我在A.cpp中定义类w时,我得到了重定义错误,这让我相信类具有内部链接.
我在这里错过了什么吗?
我需要使用mysql查询将所有双引号替换为单引号.
我怎样才能做到这一点.我的sql应该是双引号.
mysql="select replace(text,'\"',''') from mytable"
Run Code Online (Sandbox Code Playgroud)
投掷错误.如何在查询中转义单引号?
我是Java的新手,我有一个非常基本的问题.
我在同一个包下有2个父类.Animal抽象类和Machine类.
现在,AnimalAbstract Class有一个受保护的方法.我知道如果类在同一个包下,可以访问受保护的方法.
我可以在我的Machine类中访问该受保护的方法,问题是..是否可以覆盖该受保护的方法?没有扩展Animal类.
我创建了一个代表项目的简单类:
public class EntityAuftrag
{
public string cis_auftrag { get; set; }
public string bezeich { get; set; }
public DateTime? dStart { get; set; }
public DateTime? dEnd { get; set; }
public decimal? aufstunde { get; set; }
public int id_auftrag { get; set; }
public string barcolor { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
现在我列出了这些.我想提取最小的日期,我该怎么做?
如何在java中将Float转换为Integer?
Float value = 30.0F
Run Code Online (Sandbox Code Playgroud)
如何将上述值转换为Integer?
请帮我?
如何将字符串存储在varbinary(max)列中?
我在转换过程中遇到麻烦我正在这样做:
cmd.CommandText = "Insert into " + bdcombo.Text + ".dbo.nomes (id, nome) values (@id, @nome)";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlcon;
cmd.Parameters.Add("@nome", SqlDbType.VarBinary, 20).Value = Convert.ToSByte(textBox1.Text);
Run Code Online (Sandbox Code Playgroud) 我有一个基类和一个派生类,如下所示
public class animal
{
public string name { get; set; }
}
public class dog : animal
{
public int age { get; set; }
public string type { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
animal a = new animal();
dog d = new dog();
a = d; //compiled
d = a; //Error:Cannot implicitly convert type 'animal' to 'dog'.
d = (dog)a; // compiled
Run Code Online (Sandbox Code Playgroud)
内部派生类可以分配给base但是需要进行反向显式转换?即使base和derived类都包含相同的成员,也会发现相同的结果.