| |

VerySource

 Forgot password?
 Register
Search
View: 3397|Reply: 14

Ask winsock again!

[Copy link]

1

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-1-30 03:20:01
| Show all posts |Read mode
According to the following example, I can't send text!

First, add the WINSOCK control in the window:
新 Open a new window in the application, click the controls-> OLE menu item in the window artboard, and the Insert object window pops up,
Click the Insert control tab, double-click the selected Microsoft Winsock control from the list box, and paste the winsock icon on the window.
控件 The names of the controls in the program are winsock_a (Party A) and winsock_b (Party B).

Second, set the information input and output text boxes:
增加 Add a button cb_1, two single-line text boxes sle_1, sle_2 in the window, which are used to enter the string to be sent and accept the string sent by the other party.

3. Set communication protocol: WINSOCK control allows users to communicate using either UDP or TCP protocol.
1. UDP protocol setting: UDP protocol is a connectionless communication protocol. Before communication, you need to bind the remotehost and remoteport attributes. If you need two-way communication, you must also set the localport attribute.
加入 Add the following statement to the Open event of the Party A (local address: 134.1.1.1) window:
Winsock_a.object.protocol = 1 // winsock communication protocol is set to UDP protocol
Winsock_a.object.remotehost = "134.1.1.2" // IP address of the other party
Winsock_a.object.remoteport = 6000 // Winsock communication port number of the other party
Winsock_a.object.localport = 6001 // winsock communication port number of this machine
Winsock_a.object.bind // Binding communication protocol
加入 Add the following statement to the Open event of Party B's (local address: 134.1.1.2) window:
Winsock_b.object.protocol = 1 // winsock communication protocol is set to UDP protocol
Winsock_b.object.remotehost = "134.1.1.1" // The IP address of the other party
Winsock_b.object.remoteport = 6001 // Winsock communication port number of the other party
Winsock_b.object.localport = 6000 // winsock communication port number of this machine
Winsock_b.object.bin // Binding communication protocol
2. TCP protocol setting: TCP protocol needs to be connected before communication.
加入 Add the following statement to the Open event of the Party A (as the server) window:
Winsock_a.object.protocol = 0 // Winsock communication protocol is set to TCP protocol
Winsock_a.object.localport = 6001 // winsock communication port number of this machine
Winsock_a.listen () // Start listening
加入 Add the following statement to the Connectionrequest event of Party A's winsock_a control:
// After receiving the connection request from the other party
If winsock_a.object.state <> 0 then
Winsock_a.close ()
End if
Winsock_a.accept (requestID) // establish a direct connection
// requestID is the own parameter of the Connectionrequest event
加入 Add the following statement to the Open event of the Party B (as client) window:
Winsock_b.object.protocol = 0 // Winsock communication protocol is set to TCP protocol
Winsock_b.object.remotehost = "134.1.1.2" // The IP address of the other party
Winsock_b.object.remoteport = 6000 // Winsock communication port number of the other party
Winsock_b.connect () // Make a connection request
3, no matter which protocol is used, the following statement must be added to the Close event of the window:
If winsock_a / * or winsock_b * /. Object.state <> 0 then
Winsock_a.close ()
End if
Otherwise, abnormal problems may occur during the second use.

四 、 Start communication
加入 Add the following statement to the click event of button cb_1 (caption property is set to 'send'):
Winsock_a / * or winsock_b * /. Object.send (sle_1.text)
加入 Add the following statement to the dataarrival event of winsock_a / * or winsock_b * / control:
// After receiving the other party's data
String datastr1 winsock_a / * or winsock_b * /. Object.getdata (ref datastr1) sle_2.text = datastr1 // Display the data string in the text box.

Always prompt "error calling extenal object function senddata ..."
I have tried both send and senddata, and send indicates that there is no such function. senddata prompts the above error, as if the senddata function was not declared! I have tried tcp / ip, UDP mode, no! Please hero guidance!
Reply

Use magic Report

0

Threads

21

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-6-18 16:00:02
| Show all posts
Button cb_1

any a
a = sle_1.text
winsock_b.object.senddata (a)
Reply

Use magic Report

0

Threads

21

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-6-18 19:45:01
| Show all posts
winsock_b.object.remotehost="134.1.1.2" //The other party's IP address
winsock_b.object.remoteport=6000

In order to correspond, the above should be changed to
winsock_b.object.remotehost="127.0.0.1" //The other party's IP address
winsock_b.object.remoteport=6001
Reply

Use magic Report

1

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-7-9 03:30:02
| Show all posts
Upstairs, I also tried your way, the effect...

A friend who has done a LAN chat program with winsock controls will give you some advice! ~
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-3 13:45:01
| Show all posts
Go to the Internet to search winsock.pbl to understand everything, pb's OLE? Ugh...
Reply

Use magic Report

2

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-8-4 13:00:01
| Show all posts
I have used Winsock before. You can use it. Try to distinguish between upper and lower case.
Now I don’t need PB, I don’t even have PB installed on the machine, and I don’t even bother to look at the source code.
Reply

Use magic Report

2

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-8-8 01:45:01
| Show all posts
Put the winsock control on the window named Winsock1

IF Winsock1.Object.State <> 0 THEN RETURN -1

Winsock1.Object.Connect(ip, port)
//IF NOT wf_Reply_Success() THEN RETURN 1 //wf_Reply_Success waits for the return of the other party, omitted here
//Add a delay statement here, because the connection takes time
if Winsock1.Object.State> 0 //If the connection is successful, State should be = 1
Winsock1.Object.SendData( "hello")

Winsock1.Object.Close()
Reply

Use magic Report

1

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

 Author| Post time: 2020-8-8 15:45:01
| Show all posts
心系部落Your method does not seem to be able to achieve duplex, can it achieve chat functions like QQ?
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-8-8 16:30:01
| Show all posts
Writing with ole is not stable enough, just write a dll with c to send and receive
Reply

Use magic Report

2

Threads

11

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-8-8 21:45:02
| Show all posts
If you don't use ole, you can use a winsock library winsock.pbl previously provided by pb! Available on www.pdriver.com
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list