Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
2
Erster Beitrag:
vor 8 Monaten, 1 Woche
Letzter Beitrag:
vor 8 Monaten, 1 Woche
Beteiligte Autoren:
Danny Lauwers, Arekusei Timakobu

Socket in multithreading

Startbeitrag von Arekusei Timakobu am 19.12.2016 11:57

Hi!
Do someone use sockets in multithreading? I am trying to implement bidirectional socket connection with simultaneous reading/writing operation. There are two threads - one for reading and one for writing. The code is very simple (just schematic):


BUTTON Clicked Process
// Place data when buttons is clicked
PlaceSomeDataInSendingQueue()

...
// Sending procedure
PROCEDURE Sending

SocketConnect("SOCK",Port,"IP")
...
LOOP
Data is string = TakeSomeDataFromSendingQueue()
CriticalSectionStart()
SocketWrite("SOCK","data")
CriticalSectionEnd()
END

// Reading procedure
PROCEDURE Reading

...
LOOP
CriticalSectionStart()
Data is string = SocketRead("SOCK",False)
CriticalSectionEnd()
IF Data = "" THEN CONTINUE
END


On the server side I see only the first connection (1st click of button)... then no connections. Writing to socket is executing without error... so it seems the data is written but where I don't know. Any ideas?

Antworten:

Hello,

I use sockets in multi-threading. I put data in a queue from different thread and there is a sending thread that is sending this data to an other PC.

On the read side, you need to pick up the connection and start a separate thread to handle that connection. I think PC-Soft has a nice chat example that does that. I based my code on that example and it is working without problems.

Danny

von Danny Lauwers - am 19.12.2016 18:15
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.