Results 1 to 6 of 6

Thread: Am i right?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    7

    Am i right?

    i have code this 2 min ago and i want to ask if this code is right.
    I try to make a client that opens a port and the server connect to this port.(reverse connection)

    Client:

    Code:
    Option Explicit
    
    
    Private Sub client_ConnectionRequest(ByVal requestID As Long)
    
    client.Protocol = sckTCPProtocol
    client.Accept requestID
    End Sub
    
    Private Sub Command1_Click()
    client.Listen
    End Sub
    
    Private Sub Form_Load()
    client.LocalPort = "5500"
    
    
    End Sub
    Public Sub client_connect()
    
    MsgBox "connected "
    
    End Sub

    Server:

    Code:
    Option Explicit
    Private Sub Form_Load()
    server.RemoteHost = "http://n3tpum63r.homedns.org/"
    server.RemotePort = "5500"
    server.Connect
    End Sub
    
    Private Sub server_Click()
    server.Protocol = sckTCPProtocol
    End Sub
    IS this code correct?Thanx again

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Am i right?

    With just a quick glance it looks Ok.

    Have you run it? Does it work?

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    7

    Re: Am i right?

    I have run it but it doesn't give the msg box.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Am i right?

    I don't see where you are calling it.

    Do you get any errors?

  5. #5
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Am i right?

    Quote Originally Posted by netpumber
    i have code this 2 min ago and i want to ask if this code is right.
    I try to make a client that opens a port and the server connect to this port.(reverse connection)

    Client:

    Code:
    Option Explicit
    
    
    Private Sub client_ConnectionRequest(ByVal requestID As Long)
    
    client.Protocol = sckTCPProtocol
    client.Accept requestID
    End Sub
    
    Private Sub Command1_Click()
    client.Listen
    End Sub
    
    Private Sub Form_Load()
    client.LocalPort = "5500"
    
    
    End Sub
    Public Sub client_connect()
    
    MsgBox "connected "
    
    End Sub

    Server:

    Code:
    Option Explicit
    Private Sub Form_Load()
    server.RemoteHost = "http://n3tpum63r.homedns.org/"
    server.RemotePort = "5500"
    server.Connect
    End Sub
    
    Private Sub server_Click()
    server.Protocol = sckTCPProtocol
    End Sub
    IS this code correct?Thanx again
    There's quite a few things you should change. You specified LocalPort as a string when it's an integer. You put the msgbox code in the client_connect() event. It should be in the ConnectionRequest() event after the .Accept RequestID line. The connect() event only triggers when you establish a remote connection, not when someone connects to you.

    On the server, you're also specifying the RemotePort as a string. Remove the quotes. The RemoteHost cannot be set like that. You need to use an IP address or DNS name. For example: "www.vbforums.com" would be fine. "http://vbforums.com" wouldn't. You would get the error "Valid name, no data record of requested type" in the Winsock_Error() event.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Am i right?

    Quote Originally Posted by netpumber
    i have code this 2 min ago and i want to ask if this code is right.
    I try to make a client that opens a port and the server connect to this port.(reverse connection)
    Your terminology isn't correct.

    The computer that initiates the connection request is called the client. The computer that receives the first connect request is called the server. what happens after that doesn't change things. If the computer that initiates the connection is a database server, it's a server on that level, but on the networking level it's the client.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width