Chat Client with Winsock control problems 
Author Message
 Chat Client with Winsock control problems

Hi,

As a part of my project i am developing a chat client. I wanted to create a
separate class module for encapsulating the chat client so that i can just
use it from my client gui.

I want to use the winsock control in my class module. so firstly i would
like to know whether this is possible.

I declared a private variable tcpClient of type Winsock in the class module.
then when i used

set tcpClient = new Winsock    ' in the class module

it gave me "Invalid use of new"

please tell me how to use winsock control functionality from my class
module.

Thank u

Doogie



Fri, 23 Mar 2001 03:00:00 GMT  
 Chat Client with Winsock control problems
you cant just dim a new object if it is visual, you must set your tcpClient
variable to an existing winsock control.

Perhaps you could make a form (frmWinsock) with a single winsock control on
and set it to that.

So in your class module you would have :

Private fm as frmWinsock
Private ws as Winsock

private sub class_initialize()
        set fm=new frmWinsock
        set ws=fm.WinsockControl        (whatever you call the winsock control on the
form)
end sub



Fri, 23 Mar 2001 03:00:00 GMT  
 Chat Client with Winsock control problems
In globals section for class module:

Private WithEvents myWinsock As Winsock

Private Sub Class_Initialize()
    Set myWinsock = Form1.Winsock1
    Debug.Print myWinsock.LocalPort
End Sub

That is, assuming you have placed Winsock1 on the form "Form1".  This way is
not so cool, because it ties your class to the specific form.  It works
fairly well, though, if you are building an ActiveX DLL project, and the
form may be invisible anyway.  In this case, the entry point will most
definitely be your Class, so it makes sense to do the setup work in the
Class_Initialize.

For other application, you may want to use a Sub Main() entry-point, and
determine the startup mode an all that, to be more flexible.  In that case,
you will probably want to do the connection point between the Class module
and the form in the Form_Load event:

'in Class module
Public WithEvents myWinsock As Winsock

'in Form module
Private myWinsockClass As myProject.myClass

Private Sub Form_Load()
    Set myWinsockClass  = New myProject.myClass
    Set myWinsockClass.myWinsock = Winsock1
End Sub


Quote:
>Hi,

>As a part of my project i am developing a chat client. I wanted to create a
>separate class module for encapsulating the chat client so that i can just
>use it from my client gui.

>I want to use the winsock control in my class module. so firstly i would
>like to know whether this is possible.

>I declared a private variable tcpClient of type Winsock in the class
module.
>then when i used

>set tcpClient = new Winsock    ' in the class module

>it gave me "Invalid use of new"

>please tell me how to use winsock control functionality from my class
>module.

>Thank u

>Doogie



Sat, 24 Mar 2001 03:00:00 GMT  
 Chat Client with Winsock control problems
I have successfully used CreateObject to add a winsock control (with events)
to a class module, bypassing forms.

Note: The control should not appear under "Components" but under
"References", otherwise you might get a type mismatch error.

Costas Andriotis
http://users.forthnet.gr/ath/costasan/

Quote:

>In globals section for class module:

>Private WithEvents myWinsock As Winsock

>Private Sub Class_Initialize()
>    Set myWinsock = Form1.Winsock1
>    Debug.Print myWinsock.LocalPort
>End Sub

>That is, assuming you have placed Winsock1 on the form "Form1".  This way
is
>not so cool, because it ties your class to the specific form.  It works
>fairly well, though, if you are building an ActiveX DLL project, and the
>form may be invisible anyway.  In this case, the entry point will most
>definitely be your Class, so it makes sense to do the setup work in the
>Class_Initialize.

>For other application, you may want to use a Sub Main() entry-point, and
>determine the startup mode an all that, to be more flexible.  In that case,
>you will probably want to do the connection point between the Class module
>and the form in the Form_Load event:

>'in Class module
>Public WithEvents myWinsock As Winsock

>'in Form module
>Private myWinsockClass As myProject.myClass

>Private Sub Form_Load()
>    Set myWinsockClass  = New myProject.myClass
>    Set myWinsockClass.myWinsock = Winsock1
>End Sub



>>Hi,

>>As a part of my project i am developing a chat client. I wanted to create
a
>>separate class module for encapsulating the chat client so that i can just
>>use it from my client gui.

>>I want to use the winsock control in my class module. so firstly i would
>>like to know whether this is possible.

>>I declared a private variable tcpClient of type Winsock in the class
>module.
>>then when i used

>>set tcpClient = new Winsock    ' in the class module

>>it gave me "Invalid use of new"

>>please tell me how to use winsock control functionality from my class
>>module.

>>Thank u

>>Doogie



Sat, 24 Mar 2001 03:00:00 GMT  
 Chat Client with Winsock control problems
Thanks a lot for quick help

Doogie



Sun, 25 Mar 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Chat Client with Winsock control problems

2. Chat Client with Winsock control problems

3. Chat Client with Winsock control problems

4. WinSock Programming (Chat Client)

5. Having problem with multiple client winsock control

6. ftp-client problem using winsock control in visual basic 6

7. Having problem with multiple client winsock control

8. CHAT PROGRAM WITH WINSOCK - PROBLEMS

9. Problem: Chat program using Winsock

10. Winsock client problems

 

 
Powered by phpBB® Forum Software