控件的设置如下:
RemoteHost 127.0.0.1
RemotePort 12340代码如下:
UdpSocket.SendBuf(str, lengtf(str));用iris抓包无法抓到,就是说没有发出消息。不知道原因是什么,有知道的请帮个忙,第一次涉及到socket方面的编程,所以很多都不清楚。拜托知道的帮帮忙,谢谢了~~
RemoteHost 127.0.0.1
RemotePort 12340代码如下:
UdpSocket.SendBuf(str, lengtf(str));用iris抓包无法抓到,就是说没有发出消息。不知道原因是什么,有知道的请帮个忙,第一次涉及到socket方面的编程,所以很多都不清楚。拜托知道的帮帮忙,谢谢了~~
Imports System.Net
Imports System.Net.Sockets
Public Class Form1
Dim TR As New Threading.Thread(AddressOf SERVER)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim udpClient As New UdpClient()
Dim ei As New IPEndPoint(IPAddress.Parse("127.0.0.1"), 8080)
Try
' Sends a message to the host to which you have connected.
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there?") udpClient.Send(sendBytes, sendBytes.Length, ei) udpClient.Close() Catch eX As Exception
Debug.Print(eX.Message)
End Try End Sub
Sub SERVER()
Dim udpServer As New UdpClient, data(1024) As Byte
Dim ei As New IPEndPoint(IPAddress.Parse("127.0.0.1"), 8080)
udpServer.Client.Bind(ei)
data = udpServer.Receive(ei)
While data.Length > 0
Debug.Print("Server{R}:" & Encoding.ASCII.GetString(data))
data = udpServer.Receive(ei)
End While
End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TR.Start()
End Sub
End Class
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdUDPServer, IdBaseComponent, IdComponent, IdUDPBase, IdUDPClient,IdSocketHandle,
StdCtrls;type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Label2: TLabel;
Memo1: TMemo;
IdUDPClient1: TIdUDPClient;
IdUDPServer1: TIdUDPServer;
procedure Button1Click(Sender: TObject);
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
idudpclient1.Active:=true;
idudpserver1.Active:=true;
idudpclient1.Send(edit1.Text);
end;procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
var tempstream : tstringstream;
begin
tempstream:=tstringstream.Create('');
tempstream.CopyFrom(Adata,Adata.size);
memo1.Lines.Add(tempstream.DataString);end;end.