[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

TCP/IP chat app problem

Posted on 1999-11-01
11
Medium Priority
?
208 Views
Last Modified: 2013-11-13
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.
0
Comment
Question by:msali
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 6

Expert Comment

by:simonbennett
ID: 2176741
Have you set the PROTOCOL property of the control to UDP?

HTH

Simon
0
 

Expert Comment

by:ninoo
ID: 2177061
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
 

Expert Comment

by:ninoo
ID: 2177062
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 5

Expert Comment

by:AnswerTheMan
ID: 2177732
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
 

Expert Comment

by:ninoo
ID: 2177760
AnswerTheMan
   it's OK but i don't think ActiveX is not needed here.

 
0
 
LVL 5

Expert Comment

by:AnswerTheMan
ID: 2177800
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
 

Expert Comment

by:ninoo
ID: 2177865
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
 
LVL 5

Expert Comment

by:AnswerTheMan
ID: 2177922
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
 
LVL 14

Accepted Solution

by:
mcrider earned 200 total points
ID: 2177958
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
 

Expert Comment

by:ninoo
ID: 2178012
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2178038
Yes it supports multiple clients
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question