Hello people,

I first wount to say that this site is GOOD for all the people who don't know mutch about VB.
I'm very happy with you all :o
I've search with google to a help me with my problem and found this site/forum. :D

So here comes my problem and i hope someone gives me the light :mrgreen: .
(I'm jusing VB 6).

I've made a Game and a server program.
The server program only let you see whats the game sending to it.
I opend in the server 3 ports, example 21, 22, 23.
Now i have, that the game sends all his information on port 21.
But when i want to open the game again (what i mean is i open it twice) then the first game will listen on port 21 but the other game is not responding.

So my quostion is next>>> Is there a possibility that the game checks is port 21 is in juse, so yes jump then to port 22??
So that both games works, one on port 21 and teh second game on port 22 or visa versa.

I tryed it with the next code , but with no succes :confused:

Private Sub Form_Load()
'Winsock closed
Winsock1.Close
'Open ip from server in text7.text
Winsock1.RemoteHost = Text7.Text
'Open new port for server in text8.text
Winsock1.RemotePort = Text8.Text

'make contact
Winsock1.Connect

If Winsock1.RemotePort = Not 21 Then
Winsock1.RemotePort = 22
End If
If Winsock1.RemotePort = Not 22 Then
Winsock1.RemotePort = 23
End If
If Winsock1.RemotePort = Not 23 Then
Winsock1.RemotePort = 21
End If

end sub

What's wrong in my code or what must i do so to lets search the game if the port is in use and switch with the ports??

Please Help.

I've made a Game and a server program.
The server program only let you see whats the game sending to it.
I opend in the server 3 ports, example 21, 22, 23.
Now i have, that the game sends all his information on port 21.
But when i want to open the game again (what i mean is i open it twice) then the first game will listen on port 21 but the other game is not responding.

So my quostion is next>>> Is there a possibility that the game checks is port 21 is in juse, so yes jump then to port 22??
So that both games works, one on port 21 and teh second game on port 22 or visa versa.

First of all, will your server listen on the three ports (21, 22, 23) for distinct purposes, or you want to be able to control three distinct connections?

It seems it's the second one. Anyways, if you plan to accept multiple connections in the server (even if they come from the same host), you should make sure the port(s) known by the clients are *always* open and not in use.

That's done by using a winsock control array. Make the first item listen to some port as usual. On connection requests, make another available* item to accept the request id, and voila, all clients can connect to the same port!

*I mean, one whose state is not "connected".

If Winsock1.RemotePort = Not 21 Then
Winsock1.RemotePort = 22
End If
If Winsock1.RemotePort = Not 22 Then
Winsock1.RemotePort = 23
End If
If Winsock1.RemotePort = Not 23 Then
Winsock1.RemotePort = 21
End If

Only FYI, check what you are doing there. "Not 21" is -22. :rolleyes:

Thx for answering my qeustion.

It's when the game opens on port 21 and the connection is established on that port thats goor, because then my server can send info to the game with port 21.
When i op the samen game on a second pc, that the game first checks if port 21 is in use, if yes that he then opens port 22 and makes a connection with my server on port 22.
And again the same on port 23.

So winsock must look first witch port is open and witch port is close, and then make a desission what next to open.

Greetz Burnie.

I have the feeling that you have ignored my comments, but anyways....

It's when the game opens on port 21 and the connection is established on that port thats goor, because then my server can send info to the game with port 21.

I have no doubts you can establish a connection thru the port 21. ;)

When i op the samen game on a second pc, that the game first checks if port 21 is in use, if yes that he then opens port 22 and makes a connection with my server on port 22.
And again the same on port 23.

Literally, clients cannot check if a REMOTE port is in use (and BTW, doing with LOCAL ones makes no sense, because they has nothing to do with other PC's local ports). Only if it's open or not. And the only way to check that is *trying to establish a connection*.

So winsock must look first witch port is open and witch port is close, and then make a desission what next to open.

To not change what you have figured up to now, just try to .Connect to 21. If failed, try the 22. If failed, try the 23. Only remember that method will give you only three remote "bays". ;)

Hope this helps.

Hello,

Thx again for your reply.
Sorry my english reading is not so good , i'm from the netherlands. :o
I try to understand what you're trying to tell me.
The game makes a connection with port 21 so thats not the problem.
The ports i can switch, also change if neccery.
But i will try to do what you sayd in the pm.
Hopely it works, because its a very difficult command and not easy.

To not change what you have figured up to now, just try to .Connect to 21. If failed, try the 22. If failed, try the 23. Only remember that method will give you only three remote "bays".

Hopely i can figure the code out of that :rolleyes:

Hello,

Thx again for your reply.
Sorry my english reading is not so good , i'm from the netherlands. :o
I try to understand what you're trying to tell me.
The game makes a connection with port 21 so thats not the problem.
The ports i can switch, also change if neccery.
But i will try to do what you sayd in the pm.
Hopely it works, because its a very difficult command and not easy.

Hopely i can figure the code out of that :rolleyes:

Well, I try to do my best here. I'm not an english speaker either.

Basicly, the difficulty lies on that your way to look for a free port on server is pretty linear, while Winsock control is events-oriented.

The first thing you should do is to remove the three "If Winsock1.RemotePort =" blocks. I guess the first .Connect you try is on the port 21, right? well, if you cannot connect for some reason, that will send you to the Winsock1_Error event. There you can check the RemotePort and decide where to try to .Connect again.

I insist, it's not the best method to do what you require.

I insist, it's not the best method to do what you require.

Witch method do you think its the best and maybe you have a example for me??

Greetz Burny.

Witch method do you think its the best and maybe you have a example for me??

Greetz Burny.

The one I described in my 2nd post. Go here for a quick lesson with source.

The one I described in my 2nd post. Go here for a quick lesson with source.

Thx man, it works, i own you one :cheesy:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.