Bonjour a tous je me permet de faire apel a vos connaissances car g un probleme. J'ai créé un programme sur VB.net qui ouvre une connection avec un serveur voila le programme en VB.net :
Public Class Form1
Const portNumber As Integer = 8080
Dim tcpListener As New Net.Sockets.TcpListener(portNumber)
Public ServerFlag As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "Server is disabled"
ServerFlag = 0
Timer1.Interval = 100
Timer1.Enabled = True
'Label2.Text = Net.IPAddress
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ServerFlag = 0 Then
ServerFlag = 1
Button1.Text = "Stop server"
' Must listen on correct port- must be same as port client wants to connect on.
tcpListener.Start()
Label1.Text = "Server is enabled, wait for client!"
Else
ServerFlag = 0
Button1.Text = "Start server"
tcpListener.Stop()
Label1.Text = "Server is disabled"
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If ServerFlag = 1 Then
' Only if pending connection
If (tcpListener.Pending = True) Then
Timer1.Enabled = False
'Accept
Dim tcpClient As Net.Sockets.TcpClient = tcpListener.AcceptTcpClient()
Label1.Text = "Connection accepted!"
' Get the stream
Dim networkStream As Net.Sockets.NetworkStream = tcpClient.GetStream()
' Read the stream into a byte array
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
' Return the data received from the client to the console.
Dim clientdata As String = System.Text.ASCIIEncoding.ASCII.GetString(bytes)
MsgBox("Client sent: " + clientdata)
Dim responseString As String = "Connected to server ... please wait"
Dim sendBytes As [Byte]() = System.Text.ASCIIEncoding.ASCII.GetBytes(responseString)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Dim File2send As System.IO.FileStream = System.IO.File.OpenRead(".\\equinoxe.htm")
Dim FileReader As New System.IO.StreamReader(File2send)
responseString = FileReader.ReadToEnd
FileReader.Close()
File2send.Close()
Dim buff1 As [Byte]() = System.Text.ASCIIEncoding.ASCII.GetBytes(responseString)
networkStream.Write(buff1, 0, buff1.Length)
'================ envoi fichierimage ============
MsgBox("Client sent: " + clientdata)
File2send = System.IO.File.OpenRead(".\main.jpg")
Dim FileReader2 As New System.IO.StreamReader(File2send)
responseString = FileReader2.ReadToEnd
FileReader2.Close()
File2send.Close()
Dim buff2 As [Byte]() = System.Text.ASCIIEncoding.ASCII.GetBytes(responseString)
networkStream.Write(buff2, 0, buff2.Length)
'================================================
'MsgBox("Message Sent /> " + responseString)
Timer1.Enabled = True
End If
End If
End Sub
End Class
la connection serveur fonctionne ma page html s'ouvre bien mais le probleme c'est que l'image je n'arrive pas a la recuperez je la recoit en format texte je pense que sq vient de mon streamReader.
Je vous prie de bien vouloir m'aider svp je suis vraiment en galere.