TCP/IP chat app problem

Hi,
I have the following configuration for my application using WinSock control

Machine A (Server Application)
Listening Port: 9000
Sending Port  : 9001

Machine B (Client App)
Listening from Server : 9001
Sending to server     : 9000

Machine C (Client App)
Listening from Server : 9001
Sending to server     : 9000

Now when i connect Machine B to Server (A) it works fine - sending and receving

but when at the same time i connect machine (B) to Server (A) it is able to send on port 9000 but is does not receive at port 9001

i am using the WinSock control over TCP/IP

what is going on...

msa.
msaliAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

simonbennettCommented:
Have you set the PROTOCOL property of the control to UDP?

HTH

Simon
0
ninooCommented:
the problem is that my friend that VB does'nt support multi threading.your server must allow multiple clients to access u'r TCP SERVER.

one solution is dynamically give a port for your client who needs the server's access

let the server initilly hear at 9000 to a client then give him a different port so 9000 will be accessable for say some one else

ninoo
0
ninooCommented:
the problem is that my friend that VB does'nt support multi threading.your server must allow multiple clients to access u'r TCP SERVER.

one solution is dynamically give a port for your client who needs the server's access

let the server initilly hear at 9000 to a client then give him a different port so 9000 will be accessable for say some one else

ninoo
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

AnswerTheManCommented:
your approach is wrong from the start.
as mentioned - the best way for the server side is to deal with each client using a diffrent tread.
BUT - IT CAN BE DONE IN VB.
ActiveX exe is the one way to achive that.
the most simple way is to create an ActiveX EXE object that will have a public var for port number.
once the server main app gets a connection request from a client - it will create a new instance of the OBJECT, generate a UNIQ port for that object's winsock control, and accept the request for the object. then - the client will be "talking" with his own object on the server.

that's only one way possible.
0
ninooCommented:
AnswerTheMan
   it's OK but i don't think ActiveX is not needed here.

 
0
AnswerTheManCommented:
don't know why, but i have a feeling that you know what 'ActiveX control' is, but you have no idea what
 'ActiveX EXE' is.
correct me if i'm wrong.
0
ninooCommented:
AnswerTheMan
  u r absolutely wrong.i know what is ActiveX EXE is !!I just don't understand why for a TCP server u need to go for that.
 u can just do it with a standard EXE.if u find any advantages please let me know.

ninoo
0
AnswerTheManCommented:
after you'll face 100 clients jumping at once on your 1 and only thread - you'll understand. i did a long time ago.
i don't know you but what i'm talking is pure exprience in creating commercil
servers of this kind.

writing it with c++ will be only by threads creation.
VB can do it efficiantly ONLY if the principel is A thread per client.

in c++ an in windows, a THREAD is an OBJECT. = OBJECT per Client.

going with that line - ActivexX EXE is the best VB tool to achive that principal.

doing it you way, may work for few clients at a time (if you lucky). that's all.
0
mcriderCommented:
msali,

Most likely, you are having a problem where you are doing (or not doing) a "DoEvents" call

I have included a very small chat server built with the winsock control.  Use this an an example.


Cheers!

------------------------------------------------------------

1) create a project

2) add the winsock control to your project

3) add a winsock control to your form an set it's INDEX property to 0

4) add a listbox to your form and set the SORTED Property to TRUE

5) add a command button to your form

6) Paste the following code into the DECLARATION section of the form and run it.  Anyone can then telnet into this server on port 1001 and chat. You can also create your own client that will connect to this server on port 1001 if you want...



THE CODE:
---------------------------------------


Private Sub Command1_Click()
    If List1.ListIndex <> -1 Then Winsock1_Close CInt(Mid$(List1.List(List1.ListIndex), 12, 4))
End Sub

Private Sub Form_Load()
    Command1.Caption = "Disconnect"
    Winsock1(0).LocalPort = 1001
    Winsock1(0).Listen
End Sub
Private Sub Winsock1_Close(Index As Integer)
    Dim iVal As Long
       
    For iVal = 1 To Winsock1.UBound
        If Winsock1(iVal).State = sckConnected Then
            Winsock1(iVal).SendData Winsock1(Index).RemoteHostIP + " DISCONNECTED" + vbCrLf
            DoEvents
        End If
    Next iVal
    Winsock1(Index).Close
    For iVal = 0 To List1.ListCount - 1
        If InStr(1, List1.List(iVal), "Connection " + Format$(Index, "0000")) <> 0 Then
            List1.RemoveItem iVal
            Exit For
        End If
    Next iVal
    If Index = Winsock1.UBound Then
        Unload Winsock1(Index)
    End If
End Sub
Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    Dim iVal As Long
    Dim TotalConnect As Long
    Dim Acceptor As Long
       
    Acceptor = 0
    TotalConnect = 1
    For iVal = 1 To Winsock1.UBound
        Select Case Winsock1(iVal).State
            Case sckConnected
                TotalConnect = TotalConnect + 1
            Case sckClosed
                Acceptor = iVal
        End Select
    Next iVal
    If Acceptor = 0 Then Acceptor = Winsock1.Count
    If Acceptor > Winsock1.UBound Then Load Winsock1(Acceptor)
    With Winsock1(Acceptor)
        .Accept requestID
        List1.AddItem "Connection " + Format$(Acceptor, "0000") + " - " + .RemoteHostIP
        .SendData "Welcome to Telnet Chat Server" + vbCrLf + "Server hosted on " + _
            Winsock1(0).LocalIP + vbCrLf + "Total sessions connected: " + CStr(TotalConnect) + vbCrLf + vbCrLf
        DoEvents
    End With
    'ANNOUNCE THE NEW CONNECTION TO EVERYONE
    For iVal = 1 To Winsock1.UBound
        If Winsock1(iVal).State = sckConnected And iVal <> Acceptor Then
            Winsock1(iVal).SendData "From SERVER: " + Winsock1(Acceptor).RemoteHostIP + " has joined session." + vbCrLf
            DoEvents
        End If
    Next iVal
       
End Sub
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    Dim strData As String
    Dim iVal As Long
       
    Winsock1(Index).GetData strData, vbString
    Winsock1(Index).Tag = Winsock1(Index).Tag + strData
    If InStr(1, Winsock1(Index).Tag, vbCr) Then
        Winsock1(Index).SendData vbCrLf
        DoEvents
        'SEND THE BUFFER TO EVERYONE
        For iVal = 1 To Winsock1.UBound
            If Winsock1(iVal).State = sckConnected And iVal <> Index Then
                Winsock1(iVal).SendData "From " + Winsock1(Index).RemoteHostIP + ": " + Winsock1(Index).Tag
                DoEvents
            End If
        Next iVal
        Winsock1(Index).Tag = "" 
    Else
        'ECHO THE TEXT BACK TO THE LOCAL TERMINAL
        Winsock1(Index).SendData strData
    End If
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ninooCommented:
AnswerTheMan
  nice to hear that from you.to know me i am just a beginner in all these a kid...
  what our friend msali needs is something with sockets when it comes to commericial i think vb is never a good solution for that.then we will have to go for say vc or java.
 Anyway i agree with you.But still my bloody EGO does'nt allows it to the full percent
 my mailid is ninoo@enterprise-telesys.com.i'd like to here from u.

ninoo

mcrider
  hai man u had managed to put on some code above.i am not sure how reliable it is.just let me know whether it is supporting multiple clients r no

mcrider
0
mcriderCommented:
Yes it supports multiple clients
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.