Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
hi .
i've created 2 app server clinet i want to send control stream
ex: broadcast media player server/clinet i sent video from server to play it in clinet i want to send controls like play when i press play button in server i want to play in clinet and so.......more than 7 controls .
i actully wrote a code but it show me internal excption in
listener.start()
the server code is :
Imports System.Net.Sockets
Imports System.IO
Imports System.Threading


Public Class Scontrol
 Private conn As Socket
 Private thread As Thread
 Private socketstream As NetworkStream
 Private writer As BinaryWriter
 Private writer1 As BinaryWriter
 Dim listener As New TcpListener(5221)//hada port thane 4er tb3 broadcasr
 Dim counter As Integer = 1
 Dim x As Int16

 Public Sub New()
 thread = New Thread(AddressOf scontrol)//scontrol function t7t
 thread.Start()

 End Sub
 Public Sub scontrol()
 While True
 Dim listener As New TcpListener(5221)
 Dim counter As Integer = 1
 listener.Start()
 thread.Sleep(200)
 Select Case x
 Case 1
 If thread.IsAlive = True Then


 frmMain.AxWindowsMediaPlayer1.Ctlcontrols.pause()
 frmMain.AxWindowsMediaPlayer1.Ctlcontrols.pause()
 End If

 Case 2
 If thread.IsAlive Then
 frmMain.AxWindowsMediaPlayer1.Ctlcontrols.play()

 End If

 End Select


 End While
 writer.Write(x)
 End Sub


End Class

Clinet:
Imports System.Net.Sockets
Imports System.Threading
Imports System.IO

Public Class Control
 Private output As NetworkStream
 Private reader As BinaryReader
 Private writer As BinaryWriter
 Private reader1 As BinaryReader
 Dim thread As Thread
 Dim b As Int16



 Public Sub New()
 thread = New Thread(AddressOf conto)
 thread.Start()



 End Sub
 Public Sub conto()
 Try


 While True
 Dim clinet As TcpClient


 clinet = New TcpClient()
 clinet.Connect("127.0.0.1", 5221)
 output = clinet.GetStream()
 writer = New BinaryWriter(output)
 reader = New BinaryReader(output)
 reader1 = New BinaryReader(output)
 thread.Sleep(200)
 reader.ReadInt16()//begr2 int 16 bit's
 If thread.IsAlive Then
 If reader.ReadInt16 = 1 Then
 If frmMain.AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsPaused Then
 frmMain.AxWindowsMediaPlayer1.Ctlcontrols.pause()
 frmMain.Play_PictureBox.Image = My.Resources.Pause_Hover//hon b7ot pic ta3t play fe picture box ta3t play


 End If
 End If

 ElseIf reader.ReadInt16 = 2 Then
 If frmMain.AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsPlaying Then
 frmMain.AxWindowsMediaPlayer1.Ctlcontrols.play()
 frmMain.Play_PictureBox.Image=My.Resources.Play_Hover//hon 7ateet pic ta3t play

 End If

 End If






 End While
 Catch ex As Exception
 MsgBox(ex.Source)

 End Try
 End Sub
End Class

it's return to code and give me internal error in Listener.start()
please any help
thaxx
Posted
Comments
Marc A. Brown 6-May-11 13:50pm    
You need to specify the exception info for people to help you.
hamzah1 6-May-11 14:57pm    
Only one usage of each socket address (protocol/network address/port) is normally permitted
Ed Nutting 6-May-11 15:07pm    
Please see my answer. It is probably because you have a while loop that tries to create multiple listeners on the same socket. You only need one listener, it can accept multiple sockets async or synchronously.
hamzah1 6-May-11 15:43pm    
i must set the tcplistener out of the while this is why it show me this msg box thanks man alooot

1 solution

I might point out that 1) you can only ever have one tcplistener per port so why do you need a while loop? And 2) You declare 'listener' in both your class and then as an internal variable in your 'conto' method which would likely cause an exception or confusion in your code. Start cannot be called twice in a row without calling stop. If you want code to do similar sort of thing (but in C#) have a look at my article: Fast Networking Library 2[^] Which may help you. You could probably reference it (even though its c#) in your vb project to save you a lot of work.

Hope this helps,

Ed :)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-May-11 20:34pm    
Good catch; very likely the immediate reason of this problem, my 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900