我已经设置了一个服务器,它通过下面提到的 java 函数侦听加密的字节数组。早些时候,我使用 java (android) 来构建我的应用程序,因此使用相同的 java 函数很容易,但我无法弄清楚该函数的 dart 等效项(flutter)是什么,该函数接受字符串作为输入并返回 AES 加密字节数组作为输出,我可以将其写入 TCP 套接字。
另外,我非常感谢您帮助了解如何将生成的字节数组写入服务器,然后读取类似的响应并通过 dart (颤振)对其进行解密
我已经成功地编写了简单的字符串并通过 dart 接收简单的字符串作为 tcp 服务器的输入和输出,但无法对加密的字节数组执行相同的操作。在java中,我使用DataOutputStream将响应发送到服务器,如下所示
DataOutputStream dOut = newDataOutputStream(socket.getOutputStream());
byte[] s2 = Encrypt3.encrypt2(myString);
dOut.writeInt(s2.length); // write length of the message
dOut.write(s2);
Run Code Online (Sandbox Code Playgroud)
这是我用于aes加密的java函数
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
public class Encrypt3 {
public static String key = "mykey";
public static byte[] encrypt2(String text ){
String encrypt ="";
try{
// Create key and cipher
Key aesKey = new SecretKeySpec(key.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES"); …Run Code Online (Sandbox Code Playgroud) 我想查看我的项目的日志
脚步 :
我克隆了一个套接字应用程序。然后我运行npm install pm2 -g安装 pm2
我跑pm2 start
有用。它显示我的套接字应用程序的表格
但是如果我运行pm2 logs查看日志,则存在如下错误:
1|mycompany | C:\PROGRAM FILES\NODEJS\NPM.CMD:1
1|mycompany | (function (exports, require, module, __filename, __dirname) { :: Created by npm, please don't edit manually.
1|mycompany | ^
1|mycompany |
1|mycompany | SyntaxError: Unexpected token :
1|mycompany | at new Script (vm.js:79:7)
1|mycompany | at createScript (vm.js:251:10)
1|mycompany | at Object.runInThisContext (vm.js:303:10)
1|mycompany | at Module._compile (internal/modules/cjs/loader.js:657:28)
1|mycompany | at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
1|mycompany | at Module.load …Run Code Online (Sandbox Code Playgroud) 我想创建能够与多个客户端连接的服务器.我的主要功能是:
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(5556);
} catch (IOException ex) {
Logger.getLogger(MakaoServer.class.getName()).log(Level.SEVERE, null, ex);
}
while (true) {
try {
Socket connection = serverSocket.accept();
PlayerConnection playerConn = new PlayerConnection(connection);
playerConn.start();
} catch (IOException ex) {
System.out.println("Nie mo?na by?o utworzy? gniazda.");
}
}
Run Code Online (Sandbox Code Playgroud)
PlayerConnection是一个Thread类.运行方法:
public void run() {
InputStream input = null;
while (true) {
try {
input = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String msg = reader.readLine();
System.out.println(msg);
} catch (IOException ex) { …Run Code Online (Sandbox Code Playgroud) 我有一个端口上运行的serversocket,如我的服务器上的7761,ip说10.2.110.43现在有很多客户端在不同的服务器上运行,等待端口7761上的连接,并将ascii格式的数据写入该端口.
我希望serversocket验证client-ipadress,然后接受来自客户端的连接.
有没有办法做到这一点?
我创建了一个多线程客户端 - 服务器聊天应用程序,并希望用多个客户端测试我的应用程序.我打算在客户端创建一个模拟器,创建一个随机端口和IP.我的意思是我的客户端系统应该运行多个端口(不运行多次).
我试图找出在客户端类中提供客户端IP和端口号的代码部分,但无法弄清楚.我只找到了提供服务器IP和端口的部分.
这是我建立联系的一部分
private void cmdConnect_Click(object sender, System.EventArgs e)
{
try
{
//create a new client socket ...
m_socWorker = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
String szIPSelected = txtIPAddress.Text;
String szPort = txtPort.Text;
int alPort = System.Convert.ToInt16 (szPort,10);
System.Net.IPAddress remoteIPAddress = System.Net.IPAddress.Parse(szIPSelected);
System.Net.IPEndPoint remoteEndPoint = new System.Net.IPEndPoint(remoteIPAddress, alPort);
m_socWorker.Connect(remoteEndPoint);
}
catch (System.Net.Sockets.SocketException se)
{
MessageBox.Show ( se.Message );
}
}
Run Code Online (Sandbox Code Playgroud)
和我的数据发送部分
private void cmdSendData_Click(object sender, System.EventArgs e)
{
try
{
Object objData = txtData.Text;
byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString ()); …Run Code Online (Sandbox Code Playgroud) 我正在尝试开发一个Android应用程序,将图像从一个设备传输到另一个设备.然后,接收到的图像将显示在我的应用程序内的ImageView上.为了完成我的任务,我想发送一个位图的字节数组.我能够在imageview上获得第一张图片.但是,只要我点击按钮发送另一个图像,应用程序就无法发送位图.它向我显示了一个异常"java.io.IOException:Service fiscovery failed".要成功发送任何图像,我需要在接收/远程设备上重新启动我的应用程序.任何人都可以建议解决mu问题.logcat也包含在下面.
建立连接的代码:
private class StartConnectionThread extends Thread{
private final BluetoothSocket bluetoothSocket;
private final BluetoothDevice bluetoothDevice;
public StartConnectionThread(BluetoothDevice device){
BluetoothSocket tempBluetoothSocket=null;
bluetoothDevice=device;
try
{
System.out.println(uuid);
tempBluetoothSocket=device.createRfcommSocketToServiceRecord(uuid);
}
catch(IOException ioException)
{
}
bluetoothSocket=tempBluetoothSocket;
}
@Override
public void run() {
// TODO Auto-generated method stub
bluetoothAdapter.cancelDiscovery();
try
{
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
bluetoothSocket.connect();
}
catch(IOException ioException)
{
System.out.println("bluetoothSocketInThread failed");
try
{
bluetoothSocket.close();
}
catch(IOException cancelIOException)
{ …Run Code Online (Sandbox Code Playgroud) 我使用java(多线程)实现了一个客户界面.在客户端,客户在服务器已运行时登录.多个客户端可以登录为每个客户端创建一个线程.我想要实现的是当多个客户端登录时我想在服务器控制台(eclipse)中输入一个命令,该命令列出了我在控制台上输入内容后登录的所有客户端.
ClientSide代码:
btnLogin.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Connection conn = null;
try // try block
{
// declare variables
String username = "";
String pwd = "";
// get values using getText() method
username = loginEmail.getText().trim();
pwd = new String(loginPassword.getPassword());
// check condition it field equals to blank throw error
// message
if (username.equals("") || pwd.equals("")) {
JOptionPane.showMessageDialog(null, " name or password or Role is wrong", "Error",
JOptionPane.ERROR_MESSAGE);
} else // …Run Code Online (Sandbox Code Playgroud) 我试图在现有的 Spring Boot 应用程序中实现一个带有 Spring 集成的 TCP 服务器套接字,但是我遇到了一个问题,这个问题让我发疯......客户端正在向服务器发送一条消息(一个字节数组),并且超时。就是这样。我没有从服务器收到任何异常。看来我提供了错误的端口或其他东西,但检查端口后,我确信它是正确的。
这是我基于注释的配置类:
import home.brew.server.socket.ServerSocketHandler;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.ip.dsl.Tcp;
@Log4j2
@Configuration
@EnableIntegration
public class TcpServerSocketConfiguration {
@Value("${socket.port}")
private int serverSocketPort;
@Bean
public IntegrationFlow server(ServerSocketHandler serverSocketHandler) {
TcpServerConnectionFactorySpec connectionFactory =
Tcp.netServer(socketPort)
.deserializer(new CustomSerializerDeserializer())
.serializer(new CustomSerializerDeserializer())
.soTcpNoDelay(true);
TcpInboundGatewaySpec inboundGateway =
Tcp.inboundGateway(connectionFactory);
return IntegrationFlows
.from(inboundGateway)
.handle(serverSocketHandler::handleMessage)
.get();
}
@Bean
public ServerSocketHandler serverSocketHandler() {
return new ServerSocketHandler();
}
}
Run Code Online (Sandbox Code Playgroud)
我想在尝试发送答案之前使接收功能正常工作,所以这就是为什么要进行最小配置。
下面的类应该处理从服务器套接字接收到的消息
import lombok.extern.log4j.Log4j2;
import org.springframework.messaging.Message;
import …Run Code Online (Sandbox Code Playgroud) 这些天我在使用java socket时对Tcp性能感到困惑.实际上java代码非常简单.详情如下:
我发现客户端一次写入整个消息(包括结束分隔符),通信速度是否令人满意,速度可以达到每分钟50000条消息.但是,如果客户端在不同的时间内将字节写入套接字,速度会快速下降,每分钟只有1400条消息,这是原始速度的1/40倍.我很困惑.任何人都可以帮我一臂之力?任何评论表示赞赏!
我模拟的服务器端如下:
public class ServerForHelp {
final static int BUFSIZE = 10240;
Socket socket;
String delimiter = "" + (char) 28 + (char) 13;
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(9200);
System.out.println("begin to accept...");
while (true) {
Socket s = ss.accept();
Thread t = new Thread(new SocketThread1(s));
t.start();
}
}
public String readUntilDelimiter() throws Exception {
StringBuffer stringBuf = new StringBuffer();
InputStream stream = socket.getInputStream();
InputStreamReader reader …Run Code Online (Sandbox Code Playgroud) 我正在使用简单的套接字构建聊天服务器.我想知道是否可以使用python套接字服务器库和amazon ec2实例来创建基本的聊天服务器.另外,如果您有任何更好的建议,请告诉我.
serversocket ×10
java ×6
sockets ×5
.net ×1
amazon-ec2 ×1
android ×1
bluetooth ×1
c# ×1
express ×1
flutter ×1
inputstream ×1
mysql ×1
node.js ×1
outputstream ×1
performance ×1
socket.io ×1
spring-boot ×1
tcp ×1
tcpsocket ×1