我只有UDP協議的
加入一個Winsock1控制元件,一個Label1,一個text1,一個command1,一個command2
winsock1的RemoteHost設為對方IP
winsock1的LocalPort設為1000
winsock1的RemotePost設為1001
winsock1的Protocol設為1-sckUDPProtocol
command1的Caption設為“傳送”
command2的Caption設為“清屏”
text1的MuitiLine設為True
text1的ScrollBars設為2-Vertical
程式碼:
PrivateSubCommand1_Click()
Winsock1.SendDataText1.Text
Label1.Caption=Label1.Caption+"自己:"+(Chr(13))+Text1.Text+(Chr(13))
EndSub
PrivateSubCommand2_Click()
Label1.Caption=""
PrivateSubForm_Load()
Winsock1.Bind1001,LocalIP
PrivateSubWinsock1_DataArrival(ByValbytesTotalAsLong)
DimaAsString
Winsock1.GetDataa,vbString
Label1.Caption=Label1.Caption+"對方:"+(Chr(13))+a+(Chr(13))
然後新建另一個工程窗體
winsock1的LocalPort設為1001
winsock1的RemotePost設為1000
我只有UDP協議的
加入一個Winsock1控制元件,一個Label1,一個text1,一個command1,一個command2
winsock1的RemoteHost設為對方IP
winsock1的LocalPort設為1000
winsock1的RemotePost設為1001
winsock1的Protocol設為1-sckUDPProtocol
command1的Caption設為“傳送”
command2的Caption設為“清屏”
text1的MuitiLine設為True
text1的ScrollBars設為2-Vertical
程式碼:
PrivateSubCommand1_Click()
Winsock1.SendDataText1.Text
Label1.Caption=Label1.Caption+"自己:"+(Chr(13))+Text1.Text+(Chr(13))
EndSub
PrivateSubCommand2_Click()
Label1.Caption=""
EndSub
PrivateSubForm_Load()
Winsock1.Bind1001,LocalIP
EndSub
PrivateSubWinsock1_DataArrival(ByValbytesTotalAsLong)
DimaAsString
Winsock1.GetDataa,vbString
Label1.Caption=Label1.Caption+"對方:"+(Chr(13))+a+(Chr(13))
EndSub
然後新建另一個工程窗體
加入一個Winsock1控制元件,一個Label1,一個text1,一個command1,一個command2
winsock1的RemoteHost設為對方IP
winsock1的LocalPort設為1001
winsock1的RemotePost設為1000
winsock1的Protocol設為1-sckUDPProtocol
command1的Caption設為“傳送”
command2的Caption設為“清屏”
text1的MuitiLine設為True
text1的ScrollBars設為2-Vertical
程式碼:
PrivateSubCommand1_Click()
Winsock1.SendDataText1.Text
Label1.Caption=Label1.Caption+"自己:"+(Chr(13))+Text1.Text+(Chr(13))
EndSub
PrivateSubCommand2_Click()
Label1.Caption=""
EndSub
PrivateSubForm_Load()
Winsock1.Bind1001,LocalIP
EndSub
PrivateSubWinsock1_DataArrival(ByValbytesTotalAsLong)
DimaAsString
Winsock1.GetDataa,vbString
Label1.Caption=Label1.Caption+"對方:"+(Chr(13))+a+(Chr(13))
EndSub