Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.lang.visual-basic > #19142
| From | RobertoA <amorosik@tiscalinet.it> |
|---|---|
| Newsgroups | it.comp.lang.visual-basic |
| Subject | Socket communication - come renderla asincrona |
| Date | 2017-09-13 16:22 +0200 |
| Organization | C.U. srl News Server |
| Message-ID | <opbe49$ptp$1@virtdiesel.mng.cu.mi.it> (permalink) |
Uso il seguente codice per un piccolo socket server (riceve comandi da terminali remoti): ----------------------------------------------------------------- IPEndPoint ipEnd = new IPEndPoint(IPAddress.Any, 1234); Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream,ProtocolType.IP); sock.Bind(ipEnd); sock.Listen(100); Socket clientSock = sock.Accept(); byte[] clientData = new byte[1024 * 5000]; string receivedPath = "d:/"; int receivedBytesLen = clientSock.Receive(clientData); int fileNameLen = BitConverter.ToInt32(clientData, 0); string fileName = Encoding.ASCII.GetString(clientData, 4, fileNameLen); BinaryWriter bWrite = new BinaryWriter(File.Open(receivedPath + fileName, FileMode.Append)); ; bWrite.Write(clientData, 4 + fileNameLen, receivedBytesLen - 4 - fileNameLen); bWrite.Close(); clientSock.Close(); ----------------------------------------------------------------- Quando arriva l'istruzione 'Socket clientSock = sock.Accept();' il flusso programma si blocca in attesa di nuovi caratteri sul canale appena aperto Essendo in attesa da quel canale, il programma non reagisce piu' a qualsiasi stimolo, posso solo chiuderlo col task manager Come fare per attivare la ricezione via socket, mantenendo la possibilita' di usare le altre funzioni sulla form (configurazione, uscita programma, help, ..) ?
Back to it.comp.lang.visual-basic | Previous | Next — Next in thread | Find similar
Socket communication - come renderla asincrona RobertoA <amorosik@tiscalinet.it> - 2017-09-13 16:22 +0200
Re: Socket communication - come renderla asincrona Franz_aRTiglio <franzgol@N0SPAMtin.it> - 2017-09-13 17:55 +0200
Re: Socket communication - come renderla asincrona RobertoA <amorosik@tiscalinet.it> - 2017-09-14 19:12 +0200
csiph-web