導航:首頁 > 配伺服器 > 如何截獲伺服器socket數據

如何截獲伺服器socket數據

發布時間:2023-08-25 05:47:36

java socket伺服器如何捕獲並釋放無效連接

這個很簡單啊。設置超時就可以了,當超過一定時間沒有進行數據交換的話,會自動關閉的。或者寫個監護線程,查看狀態。socket還有一個方法叫isClose也可以進行判斷。樓下的是sice5921:是2貨來到的,來混分的樓主千萬別給分他,像這種拉基進來一次檢舉一次,哪怕把問題關閉了也不給這種拉基分

㈡ 網路中如何截取數據包修改後返回伺服器

截取數據包可以仿照sniffer的方法,將把網卡置於混雜模式(Raw Socket)的方法,然後抓包,分析……
另外你的網路流量監控系統是監控鏈路還是監控節點,監控節點的話直接訪問注冊表就可以了(windows),如果是監控整個網路環境的話可參考icmp協議的使用。

android socket 接收伺服器返回數據,如何查找想要的數值

Android 客戶端代碼:

package com.ltb.SCActivity;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class SCActivity extends Activity {
private TextView mRecvText = null;
private EditText mSentText = null;
private Button mSendRecvButton = null;
private Socket mSocket = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

mRecvText = (TextView)findViewById(R.id.recvText);
mSentText = (EditText)findViewById(R.id.sentText);
mSendRecvButton = (Button)findViewById(R.id.sendRecvButton);

mSendRecvButton.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

String sentMessage = mSentText.getText().toString() + "\r\n";

try {
mSocket = new Socket("10.126.38.155", 12577);

Log.i("------SCActivity---before send---", sentMessage);

PrintWriter send = new PrintWriter(new BufferedWriter(new OutputStreamWriter(mSocket.getOutputStream())));
send.println(sentMessage);
send.flush(); //Important!!!!!!
//send.write(sentMessage);
Log.i("------SCActivity---after send---", sentMessage);

BufferedReader recv = new BufferedReader(new InputStreamReader(mSocket.getInputStream()));
Log.i("------SCActivity---Before ---recv.readLine()---", sentMessage);
String recvMsg = recv.readLine();
Log.i("------SCActivity---after ---recv.readLine()---", recvMsg);
if (recvMsg != null) {
mRecvText.setText(recvMsg);
} else {
mRecvText.setText("Cannot receive data correctly.");
}

send.close();
recv.close();
mSocket.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
}

伺服器端代碼:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Server implements Runnable {
public void run() {
try {
ServerSocket serverSocket = new ServerSocket(12577);
while (true) {
Socket client = serverSocket.accept();
System.out.println("accept");
try {
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String str = in.readLine();
System.out.println("read:" + str);
PrintWriter pout = new PrintWriter(new BufferedWriter(new OutputStreamWriter(client.getOutputStream())), true);
//pout.write("Server Received Message: " + str);
pout.println("Server Received Message: " + str);

System.out.println("after send in server");
/* BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String str = in.readLine();
System.out.println("read:" + str);*/

pout.close();
in.close();
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
client.close();
System.out.println("close");
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}

public static void main(String argv[] ) {
Thread pcServerThread = new Thread(new Server());
pcServerThread.start();
}
}

閱讀全文

與如何截獲伺服器socket數據相關的資料

熱點內容
androidseekbar進度條 瀏覽:354
梯度上升演算法知乎 瀏覽:647
qt項目源碼下載 瀏覽:393
不允許代理伺服器什麼意思 瀏覽:511
盲反卷積演算法 瀏覽:306
峰火戰國什麼時候能開伺服器 瀏覽:452
加密的pdf怎麼提取和修改 瀏覽:488
壓縮空氣氣體流量計 瀏覽:845
高角杯如何編程 瀏覽:1011
哪個app可以下載迷失島 瀏覽:29
100以內程序員鍵盤 瀏覽:914
調試助手源碼是什麼 瀏覽:601
程序員網優 瀏覽:461
有沒有極限壓縮方法 瀏覽:79
岳陽hypermill五軸編程 瀏覽:385
超級舒服的解壓神器 瀏覽:450
超短macd源碼 瀏覽:166
群暉怎麼設置用戶訪問指定文件夾 瀏覽:557
安卓怎麼測觸摸屏 瀏覽:596
javastring原理 瀏覽:318