Pb application se fermant toute seul (urgent !!)

syxe_mpl Messages postés 58 Date d'inscription mercredi 15 décembre 2004 Statut Membre Dernière intervention 20 décembre 2010 - 11 juin 2007 à 09:45
syxe_mpl Messages postés 58 Date d'inscription mercredi 15 décembre 2004 Statut Membre Dernière intervention 20 décembre 2010 - 11 juin 2007 à 10:38
Bonjour,

Je dévellope des applications sous VB.net2005. J'ai réaliser un serveur de réception de données codées par internet ! Mon application utilise une base de donnée MySQL. J'ai un énorme problème ! L'application s'arrête toute seule au bou d'un moment (pb non permanant ! ALEATOIRE ) et sans message d'erreur !!!!?  En installant un petit débugage sur la base de données, je constate que cela ce produit avec la liaison sur la base de donnée ! Mais j'ai une autre application qui fonctionne de la meme façon mais sans avoir de connection IP et cette derniere ne plante pas !! Donc je ne pense pas que cela vienne de la connexion avec la base de données mais plutot au niveau de la gestion de l'objet socketIP utilisé pour gérer les connexions IP ainsi que le dialogue IP!
Aurriez vous des solutions ou quelques explications??!!!

Merci beaucoup pour toutes vos réponses ! bon code

Nico.

2 réponses

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
11 juin 2007 à 09:51
faudrait voir un peu de code pour pouvoir diagnostiquer quoi sque ce soit...

Renfield
Admin CodeS-SourceS- MVP Visual Basic
0
syxe_mpl Messages postés 58 Date d'inscription mercredi 15 décembre 2004 Statut Membre Dernière intervention 20 décembre 2010
11 juin 2007 à 10:38
ok oui il est vrai !
 
voici la classe de gestion des connexion IP : UserConnection.vb



'Option Strict On





Imports





System.Net.Sockets




Imports



System.Text




' The UserConnection class encapsulates the functionality of a TcpClient connection
' with streaming for a single user.












Public







Class





UserConnection







Const
Cts_READ_BUFFER_SIZE

As




Integer

=

255




'taille par defaut 255 paramétrable à la création de la classe









' Overload the New operator to set up a read thread.










Public



Sub




New


(

ByVal

client

As

TcpClient,

Optional




ByVal

LaTaille_Fifo_Rx

As




Integer



= Cts_READ_BUFFER_SIZE)



    Me

.client = client

    type = Enum_type.tcp 




    ReDim
readBuffer(LaTaille_Fifo_Rx)

'redimensionne le buffer à la taille souhaité




    _Taille_Fifo_Rx = LaTaille_Fifo_Rx




    ' This starts the asynchronous read thread. The data will be saved into




    ' readBuffer.




    Me
.client.GetStream.BeginRead(readBuffer,

0

, LaTaille_Fifo_Rx,

AddressOf

StreamReceiver,

Nothing



)




End



Sub









Private
client

As



TcpClient




Private



Enum



Enum_type

   tcp

   socket




End



Enum









Dim
type

As

Enum_type = Enum_type.tcp

'par defaut









Private
_Taille_Fifo_Rx

As




Integer



= Cts_READ_BUFFER_SIZE






Private
readBuffer(Cts_READ_BUFFER_SIZE)

As




Byte









Private
strName

As




String



' The Name property uniquely identifies the user connection.



Public



Property

Name()

As






String





   Get
      


Return

strName




   End



Get
   



Set
(

ByVal

Value

As




String



)
      
strName = Value
   



End



Set




End



Property










Public



Event



LineReceived (

ByVal

sender

As

UserConnection,

ByVal

Data

As




String



)




' This subroutine uses a StreamWriter to send a message to the user.



Public



Overloads




Sub



SendData(

ByVal

Data

As




String



)
   



' Synclock ensure that no other threads try to use the stream at the same time.



   SyncLock

client.GetStream




      Dim
writer

As




New



IO.StreamWriter(client.GetStream)

      writer.Write(Data & Chr(



13
) & Chr(

10



))



      ' Make sure all data is sent now.


      writer.Flush()




   End





SyncLock




End



Sub










Public



Overloads




Sub



SendData(

ByVal

Data()

As




Byte



)



' Synclock ensure that no other threads try to use the stream at the same time.


'mis en forme de la tram de byte en string




Dim
st

As




String

=

""




For
i

As




Integer

=

0




To

Data.Length -

1
   



st += Chr(Data(i))




Next





SyncLock

client.GetStream




   Dim
writer

As




New



IO.StreamWriter(client.GetStream)

   writer.Write(Mid(st,



1
, Data.Length) & Chr(

13

) & Chr(

10



))



   ' Make sure all data is sent now.


   writer.Flush()




End



SyncLock




End



Sub










Public



ReadOnly




Property

LeClient()

As





TcpClient

   



Get
      


Return

client
   



End



Get




End



Property








'This close the connection with serveur



Public



Sub





Close()
   
client.Close()




End



Sub








' This is the callback function for TcpClient.GetStream.Begin. It begins an



' asynchronous read from a stream.







Public



Event

evt_debug(

ByVal

data

As




String





)









Private



Sub

StreamReceiver(

ByVal

ar

As





IAsyncResult)






Dim
BytesRead

As




Integer




Dim
strMessage

As




String




Try




  
 ' Ensure that no other threads try to use the stream at the same time.



   SyncLock

client.GetStream




      ' Finish asynchronous read into readBuffer and get number of bytes read.




      BytesRead = client.GetStream.EndRead(ar)




   End



SyncLock



   ' Convert the byte array the message was saved into, minus one for the

   ' Chr(13).


   strMessage = Encoding.ASCII.GetString(readBuffer,


0

, BytesRead)




   If
BytesRead =

0




Then




      client.Close()




      Exit



Sub




   End





If






   RaiseEvent
evt_debug(Now.ToString +

" nb="



+ BytesRead.ToString)




   RaiseEvent
LineReceived(

Me



, strMessage)




   
   ' Ensure that no other threads try to use the stream at the same time.




   If
client.Connected =

False




Then




Exit




Sub



   SyncLock

client.GetStream




         ' Start a new asynchronous read into readBuffer.




         client.GetStream.BeginRead(readBuffer,



0
, _Taille_Fifo_Rx,

AddressOf

StreamReceiver,

Nothing



)




    End



SyncLock






   Catch
e

As



Exception




      '....
   End



Try






End





Sub

End







Class
0
Rejoignez-nous