Results 1 to 11 of 11

Thread: Someone tell me about Winsock!

  1. #1
    Guest

    Exclamation

    I was just fiddling around with components and references to see what they could do, and then Winsock popped up. I've heard about how it can make chat programs, but I never really needed to, so I just ignored it. Now it seems like a good idea. I've fiddled with it and I couldn't get it to send data.

    Can someone send me a demo program or URL, or even some code to get me started?

  2. #2
    Guest
    Go to http://www.planet-source-code.com and search Winsock. I am sure a bunch of things will come up.

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    You said "program"....


    Don't you mean "programs"?


    Winsock is a control for communication which means there needs to be something on BOTH ends for it to work.

    As well as the link given above I would do a search on http://www.microsoft.com as there are several articles about WinSock including a brief tutorial.

  4. #4
    Guest
    Yeah, but I want to make it sorta like Microsoft Chat, but without the stupid Comic version.

  5. #5
    Hyperactive Member Sacofjoea's Avatar
    Join Date
    May 2000
    Location
    Never Never Land
    Posts
    472
    actually you dont have to have a client/server to make a chat... just a client at least... Connect through Ip/Ports
    That arranged can be

  6. #6
    Guest
    I did post a tutorial on 6/23/2000 on how to make your own chat (not a tutorial written by me). Here is the link to the thread: http://forums.vb-world.net/showthrea...threadid=20540

  7. #7
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Microsoft Chat is a "Client" program.

    Somewhere there is a server running on the internet which is the "Server" application that matches this client program. It knows the protocol to use in order to communicate with the client...

    Thats why you can only connect to certain servers with Microsoft Chat.

    IRC (Internet Relay Chat) is actually a protocol in itself and uses a specific port number (6667). This means that if you were to connect to an IRC server using Winsock on that port number you would receive all of the protocol packets and providing you could work out how to "talk" to the server you could make your own chat program.


    So if you are wanting to make a program that will "talk" with existing programs such as MS Chat then you have to find out the protocol they use....

    If however you want to make your own then you simply come up with your own protocol. But you still have to either connect to a central server that is using the same protocol as you are or you need to be able to fully develop a peer-to-peer protocol that doesn't require a centralized server but is able to let everyone else in the chat know who everyone else is.... very complicated.

    If its on the internet then you would be looking for an NT server that would be the IRC server listening in on the port 6667 and then dealing with requests as they come in from a multitude of sources (1 winsock instance for EACH user that is connected). Your client application would then interface with this server using the address that you provide and talk with it in the protocol you have chosen.

  8. #8
    Guest
    Oh, now I see. Well now I have a good start. But I seem to get a lot of errors. Also, is it possible to send messages to yourself (using the loopback IP, 127.0.0.1)?

  9. #9
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    yep you can send messages to your self by using the 127.0.0.1 ip address, its the way I usually test any client and server program I make.

    make the server listen on a certain port, and make the client project connect to 127.0.0.1 on that port. to get the data recieved use the data arrival event in the winsock control and in that event put something like

    Dim IncomingData as string
    winsock1.getdata IncomingData
    Msgbox IncomingData.

    if you are still looking for a winsock example here is something extremely simple a one on one client server program

    [CODE]'Start a new project make it the server
    'the server code.
    Private Sub Form_Load()
    Winsock1.LocalPort = 5555 'sets the local port
    Winsock1.Listen 'tells the winsock control to listen
    End Sub

    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    If Winsock1.State <> sckConnected Then Winsock1.Close 'if the socket isn't already connected then close the winsock to accept the request
    Winsock1.Accept requestID 'accept the connection request
    Winsock1.SendData "Welcome to the server" 'sends some testdata

    End Sub


    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim ServerData As String
    Winsock1.GetData ServerData 'Gets the data
    MsgBox ServerData 'Displays it
    End Sub


    'Now load another instance of vb, in which the client code will go.
    'Client code


    Private Sub Command1_Click()
    Winsock1.Connect "127.0.0.1", 5555 'instruct it to connect
    End Sub

    Private Sub Winsock1_Connect()
    MsgBox "Connected" 'When a connection is established
    End Sub

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim ClientData As String
    Winsock1.GetData ClientData 'gets the data sent
    MsgBox ClientData 'displays the data
    End Sub


    'Now run the server, then run the client and try it out

    'If you want to make server that supports multiple connections that also pretty easy to do.
    'Set your servers winsock control index property to 0
    'then in the general declaration section place this code:

    'and replace all your server code with this:

    Dim AmntConnect As Integer

    Private Sub Form_Load()
    Winsock1(Index).LocalPort = 5555 'sets the local port
    Winsock1(Index).Listen 'tells the winsock control to listen
    End Sub

    Private Sub Winsock1_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    If Index = 0 Then
    AmntConnect = AmntConnect + 1
    Load Winsock1(AmntConnect) 'loads the winsock control
    Winsock1(AmntConnect).LocalPort = 0 'sets the port to a port that isn'g being used
    Winsock1(AmntConnect).Accept requestID 'accept the request
    Winsock1(AmntConnect).SendData "Welcome to the server" 'just sends some data
    End If
    End Sub

    Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    Dim ServerData As String
    Winsock1(Index).GetData ServerData 'Gets the data
    MsgBox ServerData 'Displays it
    End Sub

  10. #10
    Guest
    Thanks for that. The person I wanted to send messages to is actually behind a firewall. Maybe if I'm sneaky I can send it through a port which is already in use or something, if it's possible.

  11. #11
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    If your friend is behind a firewall and the people who set it up are not complete and utter morons then you won't have much luck in reaching him.

    If you use a port that is already being used then both of you will receive messages from that port for the things it IS being used for...

    Not only that, but there isn't a relay.

    Lets say you used the Telnet port of 23.

    This means you can connect and send messages to the Telnet Daemon. Your friend can send messages to and from the Telnet Daemon....

    But nothing in the middle will get the Telnet Daemon to send YOUR message to HIM and vice versa.

    So it makes it kind of useless. His IP address is blocked from the outside and everything goes through the proxy server which is WHY they use firewalls in the first place.

    The only way you will be able to do it is if there is an unprotected port on the proxy and both of you can connect through it and change the server that runs on the other end... and doing that would be tantamount to "hacking" and probably land you in jail ;-)

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