Hi, Thanks for taking your time and try to help me, first of all, excuse my bad english.
Well, I want to stablish a service where multiple clients sends msgs to a server, but with non permanent connection. I have made a conection between 2 pcs, but i'll try to explain with images what i want:
1.- Server is up. First Client make his socket connection:
http://imageshack.com/a/img841/8246/fkyu5.jpg[
^]
2.- Second client make his connection:
http://imagizer.imageshack.us/a/img822/3308/v4a8.jpg[
^]
3.- Third client make his connection and first client close connection:
http://imageshack.com/a/img829/4230/hwlo.jpg[
^]
That's almost what I want to do.
I'll put here my code to let you know what Am I working with
Client Code:
Imports System.Net.Sockets
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try
Dim oSocket As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Dim vDatos(500) As Byte
vDatos = System.Text.Encoding.BigEndianUnicode.GetBytes(TextBox1.Text)
oSocket.Connect(Net.IPAddress.Parse("192.168.1.100"), 60000)
oSocket.Send(vDatos)
oSocket.Disconnect(False)
oSocket.Close()
Catch er As SocketException
MsgBox(er.SocketErrorCode)
End Try
End Sub
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
End Class
Server Code
Imports System.Threading
Imports System.Net.Sockets
Public Class Form1
Private oInitSocket As TcpListener
Private nMensajes As Integer = 1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
oInitSocket = New TcpListener(Net.IPAddress.Any, 60000)
oInitSocket.Start(10)
Do
If oInitSocket.Pending = True Then
Dim oClientSocket As Socket = oInitSocket.AcceptSocket()
Dim vDatos(255) As Byte
oClientSocket.Receive(vDatos)
TextBox1.Text &= vbCrLf & "Mensaje nº " & nMensajes & ": " & _
System.Text.Encoding.BigEndianUnicode.GetString(vDatos)
oClientSocket.Disconnect(False)
oClientSocket.Close()
nMensajes += 1
TextBox1.Invalidate()
Me.Refresh()
End If
Loop
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
e.KeyChar = ""
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
End Class