ThievingSix
asked on
Listing all active connections and selecting ones to kill
Ok, the reason for the low point count on this is that I am just looking for information(although working code would allow me to up the point count).
What I'm trying to do is code a server program that interacts with a bunch of clients(500+). That I am pretty sure I can do, what I can't do is the following:
*Get a list of all active connections on a certain port
*Get rid of(Disconnect) the ones that are not connected with the server as well.
You might understand if I provide an example(Actually what it's going to be used for):
A game server has 500 people on it, the client programs have a hack protection system and I want to make sure it's running. What happens is the active connections on the server(on the game port specifically) are compared with the server hack protection which maintains a list of clients that are running the hack protection. If they are not I want to close the winsock connection that they have made.
For now all I am asking is for information that I can figure out. If someone wants to point out that they have working code I will up the point value depending on how much work I have left to do.
Thanks in advance.
What I'm trying to do is code a server program that interacts with a bunch of clients(500+). That I am pretty sure I can do, what I can't do is the following:
*Get a list of all active connections on a certain port
*Get rid of(Disconnect) the ones that are not connected with the server as well.
You might understand if I provide an example(Actually what it's going to be used for):
A game server has 500 people on it, the client programs have a hack protection system and I want to make sure it's running. What happens is the active connections on the server(on the game port specifically) are compared with the server hack protection which maintains a list of clients that are running the hack protection. If they are not I want to close the winsock connection that they have made.
For now all I am asking is for information that I can figure out. If someone wants to point out that they have working code I will up the point value depending on how much work I have left to do.
Thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
note. my solution is "low level" one, if you write your own app that maintain connections to clients your task may be acomplished in simpler way. probably you keep some kind of list of clients with connection components (Indy?) then you could simply browse your list and disconnect/delete specific connection.
ziolko.
ziolko.
ASKER
I'm going to take a look at the code you posted. I really don't mind complicated, keeps me from being bored. I'll test it out in a bit. Thanks.
ASKER
Ok I just tested it on the server. And I didn't get any of the connections of the server itself, any reason for that?
Note: I got connections with some other things, but not the game server for which this is intended.
Note: I got connections with some other things, but not the game server for which this is intended.
is your game using tcp for transport?
ziolko.
ziolko.
ASKER
Yes its TCP:
ports
TCP: 6000,8900,5100
UDP 7777,7778,8900
The one I want to know is the 6000 port. The code posted didn't show any from it.
ports
TCP: 6000,8900,5100
UDP 7777,7778,8900
The one I want to know is the 6000 port. The code posted didn't show any from it.
ASKER
OK, got the port 6000 to show connections. Only problem is that it is showing the connection IP of the server not the connector. I'm going to see if thats something that can be edited in the code.
ASKER
ListBox1.Items.Add(GetIP(i tem.dwRemo teAddr) + ' ' + IntToStr(GetPort(item.dwLo calPort))) ;
Local --> Remote..sometimes I can be blind.
Local --> Remote..sometimes I can be blind.
ASKER
Ok Getting Access error but the code works, any ideas?
procedure TForm1.Button1Click(Sender: TObject);
var
item: MIB_TCPROW_OWNER_PID;
I : Integer;
begin
ReadTCPTable;
For I := 0 To FBufferTCP^.dwNumEntries Do
begin
item := FBufferTCP^.table[I];
ListBox1.Items.Add(GetIP(item.dwRemoteAddr) + ' ' + IntToStr(GetPort(item.dwLocalPort)));
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
item: PMIB_TCPROW;
item2 : MIB_TCPROW_OWNER_PID;
begin
item2 := FBufferTCP^.table[ListBox1.ItemIndex];
item.dwState := MIB_TCP_STATE_DELETE_TCB;
item.dwLocalAddr := item2.dwLocalAddr;
item.dwLocalPort := item2.dwLocalPort;
item.dwRemoteAddr := item2.dwRemoteAddr;
item.dwRemotePort := item2.dwRemotePort;
SetTCPEntry(item);
end;
first thing, are those connections on ports 6000,8900,5100 persistent or are they open only for duration of communication?
second thing if you want udp you it's pretty same as with tcp you can use appropriate functions/data types
where this error popsup?
ziolko.
second thing if you want udp you it's pretty same as with tcp you can use appropriate functions/data types
where this error popsup?
ziolko.
ASKER
They are only open for the duration of communication. And the UDP isn't really needed.
I stepped through the code of:
item2 := FBufferTCP^.table[ListBox1 .ItemIndex ];
item.dwState := MIB_TCP_STATE_DELETE_TCB;
item.dwLocalAddr := item2.dwLocalAddr;
item.dwLocalPort := item2.dwLocalPort;
item.dwRemoteAddr := item2.dwRemoteAddr;
item.dwRemotePort := item2.dwRemotePort;
SetTCPEntry(item);
It completed everything, got to the end of the buttons procedure and then came the access violation.
I stepped through the code of:
item2 := FBufferTCP^.table[ListBox1
item.dwState := MIB_TCP_STATE_DELETE_TCB;
item.dwLocalAddr := item2.dwLocalAddr;
item.dwLocalPort := item2.dwLocalPort;
item.dwRemoteAddr := item2.dwRemoteAddr;
item.dwRemotePort := item2.dwRemotePort;
SetTCPEntry(item);
It completed everything, got to the end of the buttons procedure and then came the access violation.
try this one:
procedure TForm1.Button2Click(Sender : TObject);
var
item: MIB_TCPROW;
item2 : MIB_TCPROW_OWNER_PID;
begin
item2 := FBufferTCP^.table[ListBox1 .ItemIndex ];
item.dwState := MIB_TCP_STATE_DELETE_TCB;
item.dwLocalAddr := item2.dwLocalAddr;
item.dwLocalPort := item2.dwLocalPort;
item.dwRemoteAddr := item2.dwRemoteAddr;
item.dwRemotePort := item2.dwRemotePort;
SetTCPEntry(@item);
end;
ziolko.
procedure TForm1.Button2Click(Sender
var
item: MIB_TCPROW;
item2 : MIB_TCPROW_OWNER_PID;
begin
item2 := FBufferTCP^.table[ListBox1
item.dwState := MIB_TCP_STATE_DELETE_TCB;
item.dwLocalAddr := item2.dwLocalAddr;
item.dwLocalPort := item2.dwLocalPort;
item.dwRemoteAddr := item2.dwRemoteAddr;
item.dwRemotePort := item2.dwRemotePort;
SetTCPEntry(@item);
end;
ziolko.
ASKER
I've got to say you were quick to help with full code when I only asked for information to the right path. Thankyou very much for that.
>>I've got to say you were quick to help with full code when I only asked for information to the right path. Thankyou very much for that.
well you were lucky because I did soemthing like this a while ago, and just few weeks ago I used that when building WMI provider:)
ziolko.
well you were lucky because I did soemthing like this a while ago, and just few weeks ago I used that when building WMI provider:)
ziolko.
Yes it's Very Good :)
The GetPort, The GetIP
But i would like to know how to GetState?
Please someone could help me.
I'm so dumd, and just a newbie for the experts.
I did not post a new thread because i know I'm to late to ask for.
The GetPort, The GetIP
But i would like to know how to GetState?
Please someone could help me.
I'm so dumd, and just a newbie for the experts.
I did not post a new thread because i know I'm to late to ask for.
ASKER