Solved

How do i accept multiple TCP connections using Chilkatsoft's Socket component?

Posted on 2008-10-23
11
968 Views
Last Modified: 2010-10-26
Hello.  I have a lot of components from chilkatsoft and one i'm trying to learn right now is here:
http://www.chilkatsoft.com/refdoc/xChilkatSocketRef.html

i've looked at the examples but what i'm trying to do here is create a small program that listens on a TCP port i choose and just like any type of server app like a web server or ftp server, i want my program to listen for multiple connections etc etc.  what my plan is, is to have my app listen on the port and then have a client running another client app that runs on a schedule i provide and sends a string to the server app on the port i specify.  then the server app, based on what the string is, performs some type of action..like spawning another process etc etc..

is there anyone who has some experience with the chilkatsoft socket component that can provide me with some example code on how to achieve something like this?  i think just the "server" portion is what i would need!

thanks!
0
Comment
Question by:linuxrox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
11 Comments
 
LVL 17

Expert Comment

by:inthedark
ID: 22823264
What language are you using? If you want to us VB6 I have a class which will do exactly what you want. With no hidden code you can see the full picture.

Simply you wait for a new connection; then fire a client who listens to that one connection.

If you want to go that way let me know :~)
0
 

Author Comment

by:linuxrox
ID: 22823298
VB6.
0
 

Author Comment

by:linuxrox
ID: 22823312
that sounds cool.  now is this using chilkat or is this using winsock or something else?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Accepted Solution

by:
inthedark earned 500 total points
ID: 22823469
I also have examples for .NET but here is the VB6 example:


To start the IP server running
 
Set WServer = New ucWorld
OK = WServer.StartServer(8080, "192.168.0.3")
 
To Accept an incoming connection an event is fired on the WServer object
 
Private Sub WServer_NewConnection(Client As ucWorld)
 
List1.AddItem "New Connection: " + CStr(Client.ClientID)
 
Dim OK
 
OK = Client.ClientSendOK("Hi buddy how are you today?")
 
End Sub
 
' You then get messages sent from the client to the server. The WServer handles that event.
 
Private Sub WServer_MessageToServer(Client As ucWorld, ByVal NewClient As Boolean, MessageReceived As String, MessageToReply As String)
List1.AddItem "Message To server: " + CStr(Client.ClientID) + " " + MessageReceived
 
MessageToReply = "<HTM><BODY>OK BUDDY</BODY></HTML>"
 
End Sub
 
 
'-----------Part of ucWorld.cls
 
Public Function ServerStartOK(Port As Long, ServerIPAddresses As String, Optional Protocol As MSWinsockLib.ProtocolConstants = sckTCPProtocol)
 
' Make this instance a Server
 
Set Clients = New ucClients
 
ServerMode = True
 
On Error Resume Next
Sock.Protocol = Protocol
Sock.LocalPort = Port
Dim sIPAddresses() As String
Dim lc As Long
 
sIPAddresses() = Split(ServerIPAddresses, ";")
 
For lc = 0 To UBound(sIPAddresses)
    Sock.Bind Port, sIPAddresses(lc)
    If Err.Number <> 0 Then
        ErrD = "Cannot bind port to: " + sIPAddresses(lc) + " " + Err.Description
        ErrN = Err.Number
        ServerStartOK = False
        Exit Function
    End If
Next lc
 
 
Sock.Listen
If Err.Number <> 0 Then
    ErrD = Err.Description
    ErrN = Err.Number
    ServerStartOK = False
Else
    ServerMode = True
    ServerStartOK = True
End If
Mode = 1
 
End Function

Open in new window

0
 
LVL 17

Expert Comment

by:inthedark
ID: 22823510
The example uses Winsock.

I created a simple class that can either be a client or a server.

The server handles incoming clients, once connected they are stacked into a collection of clients.

The client allows you to connect to a server and wait for messages. Incoming messages drive an event where you can decode the message and send a response.
0
 

Author Comment

by:linuxrox
ID: 22823546
cool!  i'll have a look at this in a while!  thx again!
0
 
LVL 17

Expert Comment

by:inthedark
ID: 22823727
If you are interested I can post the whole class.
0
 

Author Comment

by:linuxrox
ID: 22823904
hey that'd be cool as well!!!  
0
 

Author Closing Comment

by:linuxrox
ID: 31509308
thanks again!! great stuff!! woohoo!
0
 
LVL 17

Expert Comment

by:inthedark
ID: 22829863
send me a mail to: nick (at) z123 (dot) co (dot) uk

I will reply with a dummy project.
0

Featured Post

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

740 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