1.å¦ä½ç¨VBåè天工å
·
2.在QQ和别人聊天窗口中自动写入内容并发送的源码vb源码应该怎么写
å¦ä½ç¨VBåèå¤©å·¥å ·
winsockä½¿ç¨ Winsock æ§ä»¶ å©ç¨ WinSock æ§ä»¶å¯ä»¥ä¸è¿ç¨è®¡ç®æºå»ºç«è¿æ¥ï¼å¹¶éè¿ç¨æ·æ°æ®ææ¥åè®® (UDP)æè ä¼ è¾æ§å¶åè®® (TCP)è¿è¡æ°æ®äº¤æ¢ãè¿ä¸¤ç§åè®®é½å¯ä»¥ç¨æ¥å建客æ·ä¸æå¡å¨åºç¨ç¨åºãä¸ Timer æ§ä»¶ç±»ä¼¼ï¼WinSock æ§ä»¶å¨è¿è¡æ¶æ¯ä¸å¯è§çãå¯è½çç¨é å建æ¶éç¨æ·ä¿¡æ¯ç客æ·ç«¯åºç¨ç¨åºï¼å¹¶å°æ¶éçä¿¡æ¯åéå°æä¸å¤®æå¡å¨ã
å建ä¸ä¸ªæå¡å¨åºç¨ç¨åºï¼ä½ä¸ºå¤ä¸ªç¨æ·çæ°æ®çæ±å ¥ç¹ã
å建âè天âåºç¨ç¨åºã éæ©é讯åè®® å¨ä½¿ç¨ WinSock æ§ä»¶æ¶ï¼é¦å éè¦èè使ç¨ä»ä¹åè®®ãå¯ä»¥ä½¿ç¨çåè®®å æ¬ TCP å UDPã两ç§åè®®ä¹é´çéè¦åºå«å¨äºå®ä»¬çè¿æ¥ç¶æï¼ TCP åè®®æ§ä»¶æ¯åºäºè¿æ¥çåè®®ï¼å¯ä»¥å°å®åçµè¯ç³»ç»ç¸æ¯ãå¨å¼å§æ°æ®ä¼ è¾ä¹åï¼ç¨æ·å¿ é¡»å 建ç«è¿æ¥ã
UDP åè®®æ¯ä¸ç§æ è¿æ¥åè®®ï¼ä¸¤å°è®¡ç®æºä¹é´çä¼ è¾ç±»ä¼¼äºä¼ éé®ä»¶ï¼æ¶æ¯ä»ä¸å°è®¡ç®æºåéå°å¦ä¸å°è®¡ç®æºï¼ä½æ¯ä¸¤è ä¹é´æ²¡ææç¡®çè¿æ¥ãå¦å¤ï¼åæ¬¡ä¼ è¾çæ大æ°æ®éåå³äºå ·ä½çç½ç»ã å°åºéæ©åªä¸ç§åè®®é常æ¯ç±éè¦å建çåºç¨ç¨åºå³å®çãä¸é¢çå 个é®é¢å°æå©äºéæ©éå®çåè®®ï¼ å¨æ¶åæ°æ®çæ¶åï¼åºç¨ç¨åºæ¯å¦éè¦å¾å°å®¢æ·ç«¯æè æå¡å¨ç确认信æ¯ï¼å¦æéè¦ï¼ä½¿ç¨ TCP åè®®ï¼å¨æ¶åæ°æ®ä¹åå 建ç«æç¡®çè¿æ¥ã
æ°æ®éæ¯å¦ç¹å«å¤§ï¼ä¾å¦å¾è±¡ä¸å£°é³æ件ï¼ï¼å¨è¿æ¥å»ºç«ä¹åï¼TCP åè®®å°ç»´æ¤è¿æ¥å¹¶ç¡®ä¿æ°æ®çå®æ´æ§ãä¸è¿ï¼è¿ç§è¿æ¥éè¦æ´å¤ç计ç®èµæºï¼å èæ¯æ¯è¾âæè´µâçã
æ°æ®åéæ¯é´æçï¼è¿æ¯å¨ä¸ä¸ªä¼è¯å ï¼ä¾å¦ï¼å¦æåºç¨ç¨åºå¨æ个任å¡å®æçæ¶åéè¦éç¥æ个计ç®æºï¼UDP åè®®æ¯æ´éå®çãUDP åè®®éååéå°éçæ°æ®ã åè®®ç设置 å¨è®¾è®¡æ¶ï¼å¯ä»¥æå¦ä¸æ¹å¼è®¾ç½®åºç¨ç¨åºä½¿ç¨çåè®®ï¼å¨âå±æ§âçªå£ä¸åå»âåè®®âï¼ç¶åéæ© sckTCPProtocol æè sckUDPProtocolãä¹å¯ä»¥ä½¿ç¨ç¨åºä»£ç æ¥è®¾ç½® Protocol å±æ§ï¼å¦ä¸æ示ï¼Winsock1.Protocol = sckTCPProtocol ç¡®å®è®¡ç®æºçå称 å¨ä¸è¿ç¨è®¡ç®æºç¸è¿æ¥çæ¶åï¼éè¦ç¥éå®ç IP å°åæè å®çâ好å¬çååâãIP å°åæ¯ä¸ä¸²æ°åï¼æ¯ä¸ä¸ªæ°å为ä¸ç»ï¼ä¸é´ç¨ç¹éå¼ï¼å½¢å¦ xxx.xxx.xxx.xxxï¼ãé常ï¼ææè®°ä½çæ¯è®¡ç®æºçâ好å¬çååâãè¦ç¡®å®è®¡ç®æºçååï¼è¯·æç §ä»¥ä¸æ¥éª¤æ§è¡ï¼ å¨è®¡ç®æºçâä»»å¡æ âä¸ï¼åå»âå¯å¨âã
å¨â设置â项ä¸ï¼åå»âæ§å¶é¢æ¿âã
åå»âç½ç»âå¾æ ã
åå»âæ è¯âé项å¡ã
å¨â计ç®æºå称âæ¡ä¸å¯ä»¥æ¾å°è®¡ç®æºçå称ã ä¸é¢æ¾å°ç计ç®æºå称å¯ä»¥ä½ä¸º RemoteHost å±æ§çå¼ãTCP è¿æ¥åæ¥ å¦æåºç¨ç¨åºè¦ä½¿ç¨ TCP åè®®ï¼é£ä¹é¦å å¿ é¡»å³å®åºç¨ç¨åºæ¯æå¡å¨è¿æ¯å®¢æ·ç«¯ãå¦æè¦å建ä¸ä¸ªæå¡å¨ç«¯ï¼é£ä¹åºç¨ç¨åºéè¦âçå¬âæå®ç端å£ãå½å®¢æ·ç«¯æåºè¿æ¥è¯·æ±æ¶ï¼æå¡å¨ç«¯è½å¤æ¥å请æ±å¹¶å»ºç«è¿æ¥ãå¨è¿æ¥å»ºç«ä¹åï¼å®¢æ·ç«¯ä¸æå¡å¨ç«¯å¯ä»¥èªç±å°äºç¸é讯ãä¸åæ¥éª¤å建ä¸ä¸ªé常ç®åçæå¡å¨ï¼è¦å建ä¸ä¸ª TCP æå¡å¨ï¼è¯·æç §ä»¥ä¸æ¥éª¤æ§è¡ï¼ å建æ°ç Standard EXE å·¥ç¨ã
å°ç¼ºççªä½çå称æ¹ä¸º frmServerã
å°çªä½çæ é¢æ¹ä¸ºâTCP æå¡å¨âã
å¨çªä½ä¸æ¾å ¥ä¸ä¸ª Winsock æ§ä»¶ï¼å¹¶å°å®çååæ¹ä¸º tcpServerã
å¨çªä½ä¸æ·»å 两个 TextBox æ§ä»¶ãå°ç¬¬ä¸ä¸ªå½å为 txtSendDataï¼ç¬¬äºä¸ªä¸º txtOutputã
为çªä½æ·»å å¦ä¸ç代ç ã Private Sub Form_Load() 'å° LocalPort å±æ§è®¾ç½®ä¸ºä¸ä¸ªæ´æ°ã 'ç¶åè°ç¨ Listen æ¹æ³ã tcpServer.LocalPort = tcpServer.Listen frmClient.Show 'æ¾ç¤ºå®¢æ·ç«¯ççªä½ã End Sub Private Sub tcpServer_ConnectionRequest _ (ByVal requestID As Long) 'æ£æ¥æ§ä»¶ç State å±æ§æ¯å¦ä¸ºå ³éçã 'å¦æä¸æ¯ï¼ 'å¨æ¥åæ°çè¿æ¥ä¹åå å ³éæ¤è¿æ¥ã If tcpServer.State <> sckClosed Then _ tcpServer.Close 'æ¥åå ·æ requestID åæ°ç 'è¿æ¥ã tcpServer.Accept requestID End Sub Private Sub txtSendData_Change() 'å为 txtSendData ç TextBox æ§ä»¶ä¸ 'å å«äºè¦åéçæ°æ®ãå½ç¨æ·å¾ææ¬æ¡ä¸ 'é®å ¥æ°æ®æ¶ï¼ä½¿ç¨ SendData æ¹æ³ 'åéè¾å ¥çå符串ã tcpServer.SendData txtSendData.Text End Sub Private Sub tcpServer_DataArrival _ (ByVal bytesTotal As Long) '为è¿å ¥çæ°æ®å£°æä¸ä¸ªåéã 'è°ç¨ GetData æ¹æ³ï¼å¹¶å°æ°æ®èµäºå为 txtOutput 'ç TextBox ç Text å±æ§ã Dim strData As String tcpServer.GetData strData txtOutput.Text = strData End Sub ä¸é¢çæ¥éª¤å建äºä¸ä¸ªç®åçæå¡å¨åºç¨ç¨åºã为äºä½¿å®è½å¤å·¥ä½ï¼è¿å¿ 须为å®å建ä¸ä¸ªå®¢æ·ç«¯çåºç¨ç¨åºãè¦å建 TCP 客æ·ç«¯ï¼è¯·æç §ä»¥ä¸æ¥éª¤æ§è¡ï¼ å¨å·¥ç¨ä¸æ·»å ä¸ä¸ªæ°ççªä½ï¼å°å ¶å½å为 frmClientã
å°çªä½çæ é¢æ¹ä¸ºâTCP Clientâã
å¨çªä½ä¸æ·»å ä¸ä¸ª Winsock æ§ä»¶ï¼å¹¶å°å ¶å½å为 tcpClientã
å¨ frmClient ä¸æ·»å 两个 TextBox æ§ä»¶ãå°ç¬¬ä¸ä¸ªå½å为 txtSendï¼ç¬¬äºä¸ªä¸º txtOutputã
å¨çªä½ä¸æ¾ä¸ä¸ª CommandButton æ§ä»¶ï¼å¹¶å°å ¶å½å为 cmdConnectã
å° CommandButton æ§ä»¶çæ é¢æ¹ä¸º Connectã
å¨çªä½ä¸æ·»å å¦ä¸ç代ç ã éç¹ å¿ é¡»å° RemoteHost å±æ§å¼ä¿®æ¹ä¸ºæ¨ç计ç®æºçååãPrivate Sub Form_Load() 'Winsock æ§ä»¶çåå为 tcpClientã '注æï¼è¦æå®è¿ç¨ä¸»æºï¼å¯ä»¥ä½¿ç¨ ' IP å°åï¼ä¾å¦ï¼"..1.1"ï¼ï¼ä¹å¯ä»¥ä½¿ç¨ '计ç®æºçâ好å¬çååâå¦ä¸æ示ã tcpClient.RemoteHost = "RemoteComputerName" tcpClient.RemotePort = End Sub Private Sub cmdConnect_Click() 'è°ç¨ Connect æ¹æ³ï¼åå§åè¿æ¥ã tcpClient.Connect End Sub Private Sub txtSendData_Change() tcpClient.SendData txtSend.Text End Sub Private Sub tcpClient_DataArrival _ (ByVal bytesTotal As Long) Dim strData As String tcpClient.GetData strData txtOutput.Text = strData End Sub ä¸é¢ç代ç å建äºä¸ä¸ªç®åç客æ·/æå¡å¨æ¨¡å¼çåºç¨ç¨åºãæ们å¯ä»¥å°ä¸¤è é½è¿è¡èµ·æ¥ï¼è¿è¡å·¥ç¨ï¼ç¶ååå»âè¿æ¥âãå¨ä¸¤ä¸ªçªä½ä¹ä¸ç txtSendData ææ¬æ¡ä¸é®å ¥ææ¬ï¼å¯ä»¥çå°åæ ·çæåå°åºç°å¨å¦ä¸ä¸ªçªä½ç txtOutput ææ¬æ¡ä¸ãæ¥åå¤ä¸ªè¿æ¥è¯·æ± ä¸é¢è®¾è®¡çåºæ¬æå¡å¨åªè½æ¥åä¸ä¸ªè¿æ¥è¯·æ±ãéè¿å建æ§ä»¶æ°ç»ï¼ä½¿ç¨ä¸ä¸ªæ§ä»¶ä¹å¯ä»¥åæ¶æ¥åå¤ä¸ªè¿æ¥è¯·æ±ãå©ç¨è¿ç§æ¹æ³ï¼ä¸éè¦å ³éè¿æ¥ï¼èåªéå建æ°çæ§ä»¶å®ä¾ï¼éè¿è®¾ç½®å ¶ç´¢å¼å±æ§ï¼ï¼ç¶åå¨æ°çå®ä¾ä¸è°ç¨ Accept æ¹æ³ãä¸é¢ç代ç åå®å为 sckServer ççªä½ä¸æä¸ä¸ª Winsock æ§ä»¶ï¼å®ç Index å±æ§è¢«è®¾ç½®ä¸º 0ï¼å æ¤æ§ä»¶æ¯æ§ä»¶æ°ç»çä¸é¨åãå¨å£°æé¨åï¼å£°æäºä¸ä¸ªæ¨¡å级çåé intMaxãå¨çªä½ç Load äºä»¶ä¸ï¼intMax 被设置为 0ï¼æ°ç»ä¸ç¬¬ä¸ä¸ªæ§ä»¶ç LocalPort å±æ§è¢«è®¾ç½®ä¸º ãç¶åè°ç¨æ§ä»¶ç Listen æ¹æ³ï¼ä½¿ä¹æ为âçå¬âæ§ä»¶ãå¨è¿æ¥è¯·æ±å°è¾¾æ¶ï¼ä»£ç å°æ£æµ Index æ¯å¦ä¸º 0ï¼âçå¬âæ§ä»¶çå¼ï¼ãå¦æ为 0ï¼çå¬æ§ä»¶å°å¢å intMax çå¼ï¼å¹¶ä½¿ç¨è¯¥å·ç æ¥å建æ°çæ§ä»¶å®ä¾ãç¶åï¼ä½¿ç¨æ°çæ§ä»¶å®ä¾æ¥åè¿æ¥è¯·æ±ãPrivate intMax As Long Private Sub Form_Load() intMax = 0 sckServer(0).LocalPort = sckServer(0).Listen End Sub Private Sub sckServer_ConnectionRequest _ (Index As Integer, ByVal requestID As Long) If Index = 0 Then intMax = intMax + 1 Load sckServer(intMax) sckServer(intMax).LocalPort = 0 sckServer(intMax).Accept requestID Load txtData(intMax) End If End Sub UDP åæ¥ å建 UDP åºç¨ç¨åºæ¯å建 TCP åºç¨ç¨åºè¿è¦ç®åï¼å 为 UDP åè®®ä¸éè¦æ¾å¼çè¿æ¥ãå¨ä¸é¢ç TCP åºç¨ç¨åºä¸ï¼ä¸ä¸ª Winsock æ§ä»¶å¿ é¡»æ¾å¼å°è¿è¡âçå¬âï¼å¦ä¸ä¸ªå¿ é¡»ä½¿ç¨ Connect æ¹æ³åå§åè¿æ¥ãUDP åè®®ä¸éè¦æ¾å¼çè¿æ¥ãè¦å¨ä¸¤ä¸ªæ§ä»¶ä¸é´åéæ°æ®ï¼éè¦å®æ以ä¸çä¸æ¥ï¼å¨è¿æ¥çåæ¹ï¼ï¼ å° RemoteHost å±æ§è®¾ç½®ä¸ºå¦ä¸å°è®¡ç®æºçå称ã
å° RemotePort å±æ§è®¾ç½®ä¸ºç¬¬äºä¸ªæ§ä»¶ç LocalPort å±æ§ã
è°ç¨ Bind æ¹æ³ï¼æå®ä½¿ç¨ç LocalPortãï¼ä¸é¢å°è¯¦ç»å°è®¨è®ºè¯¥æ¹æ³ãï¼ å 为两å°è®¡ç®æºçå°ä½å¯ä»¥çæâå¹³ççâï¼è¿ç§åºç¨ç¨åºä¹è¢«ç§°ä¸ºç¹å°ç¹çã为äºå ·ä½è¯´æè¿ä¸ªé®é¢ï¼ä¸é¢å°å建ä¸ä¸ªâè天âåºç¨ç¨åºï¼ä¸¤ä¸ªäººå¯ä»¥éè¿å®è¿è¡å®æ¶ç交è°ãè¦å建ä¸ä¸ª UDP ä¼ä¼´ï¼è¯·æç §ä»¥ä¸æ¥éª¤æ§è¡ï¼ å建ä¸ä¸ªæ°ç Standard EXE å·¥ç¨ã
å°ç¼ºçççªä½çå称修æ¹ä¸º frmPeerAã
å°çªä½çæ é¢ä¿®æ¹ä¸ºâPeer Aâã
å¨çªä½ä¸æ¾å ¥ä¸ä¸ª Winsock æ§ä»¶ï¼å¹¶å°å ¶å½å为 udpPeerAã
å¨âå±æ§â页ä¸ï¼åå»âåè®®â并å°å议修æ¹ä¸º UDPProtocolã
å¨çªä½ä¸æ·»å 两个 TextBox æ§ä»¶ãå°ç¬¬ä¸ä¸ªå½å为 txtSendï¼ç¬¬äºä¸ªå½å为 txtOutputã
为çªä½å¢å å¦ä¸ç代ç ã Private Sub Form_Load() 'æ§ä»¶çåå为 udpPeerA With udpPeerA 'éç¹:å¿ é¡»å° RemoteHost çå¼ 'ä¿®æ¹ä¸ºè®¡ç®æºçååã .RemoteHost= "PeerB" .RemotePort = 'è¿æ¥ç端å£å·ã .Bind 'ç»å®å°æ¬å°ç端å£ã End With frmPeerB.Show 'æ¾ç¤ºç¬¬äºä¸ªçªä½ã End Sub Private Sub txtSend_Change() 'å¨é®å ¥ææ¬æ¶ï¼ç«å³å°å ¶åéåºå»ã udpPeerA.SendData txtSend.Text End Sub Private Sub udpPeerA_DataArrival _ (ByVal bytesTotal As Long) Dim strData As String udpPeerA.GetData strData txtOutput.Text = strData End Sub è¦å建第äºä¸ª UDP ä¼ä¼´ï¼è¯·æç §ä»¥ä¸æ¥éª¤æ§è¡ï¼ å¨å·¥ç¨ä¸æ·»å ä¸ä¸ªæ åçªä½ã
å°çªä½çååä¿®æ¹ä¸º frmPeerBã
å°çªä½çæ é¢ä¿®æ¹ä¸ºâPeer Bâã
å¨çªä½ä¸æ¾å ¥ä¸ä¸ª Winsock æ§ä»¶ï¼å¹¶å°å ¶å½å为 udpPeerBã
å¨âå±æ§â页ä¸ï¼åå»âåè®®â并å°å议修æ¹ä¸ºâUDPProtocolâã
å¨çªä½ä¸æ·»å 两个 TextBox æ§ä»¶ãå°ç¬¬ä¸ä¸ªå½å为 txtSendï¼ç¬¬äºä¸ªå½å为 txtOutputã
å¨çªä½ä¸æ·»å å¦ä¸ç代ç ã Private Sub Form_Load() 'æ§ä»¶çåå为 udpPeerBã With udpPeerB 'éç¹:å¿ é¡»å° RemoteHost çå¼æ¹ä¸º '计ç®æºçååã .RemoteHost= "PeerA" .RemotePort = 'è¦è¿æ¥ç端å£ã .Bind 'ç»å®å°æ¬å°ç端å£ä¸ã End With End Sub Private Sub txtSend_Change() 'å¨é®å ¥åç«å³åéææ¬ã udpPeerB.SendData txtSend.Text End Sub Private Sub udpPeerB_DataArrival _ (ByVal bytesTotal As Long) Dim strData As String udpPeerB.GetData strData txtOutput.Text = strData End Sub å¦æè¦è¯ç¨ä¸é¢çä¾åï¼æ F5 é®è¿è¡å·¥ç¨ï¼ç¶åå¨ä¸¤ä¸ªçªä½ç txtSend TextBox ä¸åå«é®å ¥ä¸äºææ¬ãé®å ¥çæåå°åºç°å¨å¦ä¸ä¸ªçªä½ç txtOutput TextBox ä¸ãå ³äº Bind æ¹æ³ å¨ä¸é¢ç代ç ä¸ï¼å¨å建 UDP åºç¨ç¨åºæ¶è°ç¨äº Bind æ¹æ³ï¼è¿æ¯å¿ é¡»çãBind æ¹æ³çä½ç¨æ¯ä¸ºæ§ä»¶âä¿çâä¸ä¸ªæ¬å°ç«¯å£ãä¾å¦ï¼å¦æå°æ§ä»¶ç»å®å° å·ç«¯å£ï¼é£ä¹å ¶å®åºç¨ç¨åºå°ä¸è½ä½¿ç¨è¯¥ç«¯å£è¿è¡âçå¬âã该æ¹æ³é»æ¢å ¶å®åºç¨ç¨åºä½¿ç¨åæ ·ç端å£ãBind æ¹æ³ç第äºä¸ªåæ°æ¯ä»»éçãå¦æ计ç®æºä¸åå¨å¤ä¸ªç½ç»éé å¨ï¼å¯ä»¥ç¨ LocalIP åæ°æ¥æå®ä½¿ç¨åªä¸ä¸ªéé å¨ãå¦æ忽ç¥è¯¥åæ°ï¼æ§ä»¶ä½¿ç¨çå°æ¯è®¡ç®æºä¸âæ§å¶é¢æ¿â设置ä¸âç½ç»âæ§å¶é¢æ¿å¯¹è¯æ¡ä¸ååºç第ä¸ä¸ªéé å¨ãå¨ä½¿ç¨ UDP åè®®çæ¶åï¼å¯ä»¥ä»»æå°æ¹å RemoteHost å RemotePort å±æ§ï¼åæ¶å§ç»ä¿æç»å®å¨åä¸ä¸ª LocalPort ä¸ãTCP åè®®ä¸æ¤ä¸åï¼å¨æ¹å RemoteHost å RemotePort å±æ§ä¹åï¼å¿ é¡»å å ³éè¿æ¥ã
在QQ和别人聊天窗口中自动写入内容并发送的vb源码应该怎么写
Private Sub Command1_Click()
AppActivate "你的QQ聊天窗口标题栏名字"
SendKeys "什么内容" & vbCrlf
End Sub
用这个命令,就行了
聊天vue cli源码分析