Now I want to send a string of data to the destination port, please send the function of how to write, I use the send or write is run time said that is not defined, or have some example, send a trouble can be used to me, don't copy on the Internet,,,, thank you!
CodePudding user response:
You need to create objectsWs=create WinSock
Then call
Choose a case iEvent
Case ws. FD_CONNECT
If iRet=1 then
Lb_1. AddItem (sMsg + String (Today (), "yyyy/mm/dd)" + String (Now (), "hh: mm: ss FFF"))
The else
Lb_1. AddItem (sMsg)
End the if
Case ws. FD_READ
If iRet=1 then
Lb_1. AddItem (sMsg)
Wf_save_record (sMsg)
The else
Lb_1. AddItem (sMsg)
End the if
Case ws. FD_WRITE
If iRet=1 then
Lb_1. AddItem (sMsg)
The else
Lb_1. AddItem (sMsg)
End the if
Case ws. FD_CLOSE
Lb_1. AddItem (sMsg + String (Today (), "yyyy/mm/dd)" + String (Now (), "hh: mm: ss FFF"))
The end choose
CodePudding user response:
Whether properties not adjustableCodePudding user response:
Following a simple program, for example, the WINSOCK control in the use of PB:A WINSOCK control is added in the window:
In the application to open a new window, click in the window panel controls - & gt; OLE menu items, pop-up Insert object window, click the Insert control TAB, double-click the selected from the list box Microsoft Winsock control, will the Winsock icon on the window,
The control in the program name as winsock_a (party a) and winsock_b (party b),
Second, set up information input and output text box:
Increase cb_1 a button in the window, two single line text box sle_1 sle_2, used in the input string to be sent separately send strings and to accept each other,
Three, set up the communication protocol:
WINSOCK control allows users to UDP and TCP protocol in the choose a kind of communication,
1. The UDP protocol Settings: communication UDP is a connectionless protocol, before the communication, need binding remotehost and remoteport property, if you need a two-way communication, but also set localport properties,
In the party a (the machine address is: 134.1.1.1) window Open event to add the following statement:
Winsock_a. Object. The protocol=1
//winsock communications protocol is set to the UDP protocol
Winsock_a. Object. Remotehost="134.1.1.2"
//the other IP address
Winsock_a. Object. Remoteport=6000
//the other side of the winsock communications port
Winsock_a. Object. Localport=6001
//the native winsock communications port
Winsock_a. Object. The bind
//binding communication protocol
In party b (the machine address is: 134.1.1.2) window Open event to add the following statement:
Winsock_b. Object. The protocol=1
//winsock communications protocol is set to the UDP protocol
Winsock_b. Object. Remotehost="134.1.1.1"
//the other IP address
Winsock_b. Object. Remoteport=6001
//the other side of the winsock communications port
Winsock_b. Object. Localport=6000
//the native winsock communications port
Winsock_b. Object. Bin
//binding communication protocol
2. The TCP protocol: TCP protocol in communication before the need to connect,
In party a's (as a server-side) window Open event to add the following statement:
Winsock_a. Object. The protocol=0
//winsock communications protocol to TCP protocol
Winsock_a. Object. Localport=6001
//the native winsock communications port
Winsock_a. Listen ()
//start listening
In party a's winsock_a controls Connectionrequest event to add the following statement:
//to accept connections to each other after
If winsock_a. Object. State<> 0 then
Winsock_a. Close ()
End the if
Winsock_a. Accept (requestID)
Establishing a direct connection//
//requestID Connectionrequest event own parameter
In the party b (as the client) window Open event to add the following statement:
Winsock_b. Object. The protocol=0
//winsock communications protocol to TCP protocol
Winsock_b. Object. Remotehost="134.1.1.2"
//the other IP address
Winsock_b. Object. Remoteport=6000
//the other side of the winsock communications port
Winsock_b. The connect ()//a connection request
3. Either agreement, should be in the Close of the event window to add the following statement:
If or winsock_b winsock_a/* */. Object. State<> 0 then
Winsock_a. Close ()
End the if
Otherwise may second abnormal problems when using the
Fourth, communication
The button cb_1 (caption attribute set to "send") added to the click event of the following statement:
Or winsock_b winsock_a/* */. Object. The send (sle_1. Text)
In or winsock_b winsock_a/* */controls dataarrival event to add the following statement:
//acceptance to each other after data
String datastr1
Or winsock_b winsock_a/* */. Object. Getdata (def datastr1)
Sle_2. Text=datastr1//will display data string in the text box
CodePudding user response:
I am do according to this, but when sending is not ok, if the possible, I hope you can send me see, thank youCodePudding user response:
Whether to insert not winsock controlAnother may be associated with pb version
CodePudding user response:
People with would make a can give me a look, and soon,,, infinite gratitude