91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 612KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2021-06-11
  • 語言: 其他
  • 標簽: Socket??

資源簡介

包含整個系列: Socket實戰(zhàn)系列: Socket實戰(zhàn)——UDP連接:https://blog.csdn.net/haoranhaoshi/article/details/86601468 Socket實戰(zhàn)——TCP連接:https://blog.csdn.net/haoranhaoshi/article/details/86601522 Socket實戰(zhàn)——查詢數(shù)據(jù)庫:https://blog.csdn.net/haoranhaoshi/article/details/86601566 Socket實戰(zhàn)——監(jiān)聽數(shù)據(jù)庫:https://blog.csdn.net/haoranhaoshi/article/details/86601584 Socket實戰(zhàn)——聊天:https://blog.csdn.net/haoranhaoshi/article/details/86601771 Socket實戰(zhàn)——文件上傳:https://blog.csdn.net/haoranhaoshi/article/details/86601850

資源截圖

代碼片段和文件信息

package?ChatByUDP;

import?javafx.application.Application;
import?javafx.application.Platform;
import?javafx.scene.Scene;
import?javafx.scene.control.*;
import?javafx.scene.layout.Pane;
import?javafx.stage.Stage;
import?javafx.stage.WindowEvent;

import?java.io.IOException;
import?java.net.*;

public?class?AnotherChatParticipant?extends?Application?{

????public?static?void?main(String[]?args)?{
????????launch(args);
????}

????@Override
????public?void?start(Stage?primaryStage)?{
????????TextField?textField?=?new?TextField();

????????Button?button?=?new?Button(“發(fā)送“);
????????button.setTranslateX(140);
????????button.setOnAction(event?->?{
????????????String?content?=?textField.getText();
????????????if(content?==?null?||?content.equals(““)){
????????????????Alert?alert?=?new?Alert(Alert.AlertType.WARNING?“請輸入發(fā)送內容“?ButtonType.OK);
????????????????alert.show();
????????????????return;
????????????}

????????????byte[]?message?=?content.getBytes();
????????????try?{
????????????????DatagramSocket?datagramSocket?=?new?DatagramSocket();
????????????????//?數(shù)據(jù)包發(fā)往IP:127.0.0.1,端口:10002
????????????????DatagramPacket?datagramPacket?=?new?DatagramPacket(message?message.length?InetAddress.getByName(“127.0.0.1“)?10002);
????????????????datagramSocket.send(datagramPacket);
????????????}?catch?(UnknownHostException?e)?{
????????????????e.printStackTrace();
????????????}?catch?(SocketException?e)?{
????????????????e.printStackTrace();
????????????}?catch?(IOException?e)?{
????????????????e.printStackTrace();
????????????}
????????});

????????Label?label?=?new?Label();
????????label.setTranslateY(50);
????????new?Thread(()?->?{
????????????try?{
????????????????//?創(chuàng)建IP:127.0.0.1,端口:10003的Socket監(jiān)聽
????????????????DatagramSocket?datagramSocket?=?new?DatagramSocket(10003?InetAddress.getByName(“127.0.0.1“));
????????????????while?(true)?{
????????????????????byte[]?receivedData?=?new?byte[1024];
????????????????????DatagramPacket?datagramPacket?=?new?DatagramPacket(receivedData?receivedData.length);
????????????????????datagramSocket.receive(datagramPacket);
????????????????????//?未收到則后續(xù)不執(zhí)行
????????????????????Platform.runLater(()?->
????????????????????????????label.setText(new?String(datagramPacket.getData()?0?datagramPacket.getLength()))
????????????????????);
????????????????}
????????????}?catch?(UnknownHostException?e)?{
????????????????e.printStackTrace();
????????????}?catch?(SocketException?e)?{
????????????????e.printStackTrace();
????????????}?catch?(IOException?e)?{
????????????????e.printStackTrace();
????????????}
????????}).start();

????????primaryStage.settitle(“AnotherChatParticipant“);
????????Pane?pane?=?new?Pane(textField?button?label);
????????primaryStage.setScene(new?Scene(pane?400?200));
????????primaryStage.setX(500);
????????primaryStage.setY(100);
????????primaryStage.show();

????????primaryStage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-01-20?18:17??SocketTest\
?????目錄???????????0??2019-01-22?21:42??SocketTest\.idea\
?????目錄???????????0??2019-01-21?10:22??SocketTest\.idea\libraries\
?????文件?????????288??2019-01-21?10:22??SocketTest\.idea\libraries\lib.xml
?????文件?????????276??2019-01-19?13:49??SocketTest\.idea\misc.xml
?????文件?????????267??2019-01-19?13:49??SocketTest\.idea\modules.xml
?????文件????????8915??2019-01-19?14:02??SocketTest\.idea\uiDesigner.xml
?????文件???????35858??2019-01-22?21:42??SocketTest\.idea\workspace.xml
?????文件?????????495??2019-01-20?18:17??SocketTest\SocketTest.iml
?????目錄???????????0??2019-01-21?10:21??SocketTest\lib\
?????文件???????94360??2018-02-04?21:02??SocketTest\lib\json.jar
?????文件??????540852??2016-05-07?09:18??SocketTest\lib\mysql-connector-java-5.0.8-bin.jar
?????目錄???????????0??2019-01-19?14:16??SocketTest\out\
?????目錄???????????0??2019-01-19?14:16??SocketTest\out\production\
?????目錄???????????0??2019-01-22?21:30??SocketTest\out\production\SocketTest\
?????目錄???????????0??2019-01-21?16:56??SocketTest\out\production\SocketTest\ChatByUDP\
?????文件????????5495??2019-01-21?16:56??SocketTest\out\production\SocketTest\ChatByUDP\AnotherChatParticipant.class
?????文件????????5458??2019-01-21?16:56??SocketTest\out\production\SocketTest\ChatByUDP\ChatParticipant.class
?????目錄???????????0??2019-01-22?21:31??SocketTest\out\production\SocketTest\FileUploadByTCP\
?????文件????????5556??2019-01-22?21:30??SocketTest\out\production\SocketTest\FileUploadByTCP\FileUploadClient.class
?????文件????????4794??2019-01-22?21:30??SocketTest\out\production\SocketTest\FileUploadByTCP\FileUploadServer.class
?????文件???????????4??2019-01-21?16:56??SocketTest\out\production\SocketTest\FileUploadByTCP\test1.txt
?????文件???????????4??2019-01-22?21:31??SocketTest\out\production\SocketTest\FileUploadByTCP\test2.txt
?????目錄???????????0??2019-01-22?21:30??SocketTest\out\production\SocketTest\TCP\
?????文件????????5207??2019-01-22?21:30??SocketTest\out\production\SocketTest\TCP\TCPClient.class
?????文件????????4698??2019-01-22?21:30??SocketTest\out\production\SocketTest\TCP\TCPServer.class
?????目錄???????????0??2019-01-22?21:19??SocketTest\out\production\SocketTest\TableListenerByUDP\
?????文件????????7546??2019-01-22?21:19??SocketTest\out\production\SocketTest\TableListenerByUDP\ListenTableClient.class
?????文件????????8241??2019-01-22?21:19??SocketTest\out\production\SocketTest\TableListenerByUDP\ListenTableServer.class
?????目錄???????????0??2019-01-21?14:37??SocketTest\out\production\SocketTest\TableSelectByTCP\
?????文件????????5841??2019-01-21?10:47??SocketTest\out\production\SocketTest\TableSelectByTCP\SelectTableClient.class
............此處省略25個文件信息

評論

共有 條評論