I'm working with VB.NET
So I have a server that broadcast it's own IP every second
Private Sub IPBroadcastTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IPBroadcastTimer.Tick
BroadcastIP()
End Sub
Do I have to keep broadcasting it every second for clients to pick it up after several minutes or hours?
If so, how would I set the server to listen to logins?
Here's what happens client-side and server-side:
Server : "Broadcasts IP every second" > "Listens to incoming transmissions" > "receives 3 strings [username/pass/ip]" > "Checks username and password validity on local XML file" > "sends confirmation or denial to target IP"
Client : "Listens to server broadcast" > "Receives Server IP" > "Sends 3 Strings through a form: username, password and local IP" > "Listen to server's confirmation or denial"
I used this to send, but listening doesn't seem to work...
Public EndPoint As New IPEndPoint(IPAddress.Parse("255.255.255.255"), 1001) ''Send destination port
Public EndPoint2 As New IPEndPoint(IPAddress.Any, 2001) ''Receive destination port
Public UserIPEndPoint As New IPEndPoint(IPAddress.Any, 2001)
Public UsernameEndPoint As New IPEndPoint(IPAddress.Any, 2001)
Public PassEndPoint As New IPEndPoint(IPAddress.Any, 2001)
Public Send As New UdpClient(2001) ''Send source port
Public Receive As New UdpClient(1001) '' Receive source port
Sending:
Send.Send(IPInBytes, IPInBytes.Length, EndPoint)
Receiving:
Receive.Receive(UserIPEndPoint)
How do I solve this?
What is the purpose of the broadcast? If it is for consumers to detect the service, perhaps it's better to rely on already developed protocols for this (such as Bonjour or SSDP). Like in at least SSDP, a consumer can broadcast a question ("is anybody there?") to which services may reply. Services may also spontaneously broadcast their presence, for instance when they are started, so that consumers with an ongoing detection can find them.
Related
We can use C# code or performance monitor in windows server to view current connections to IIS website.
PerformanceCounter performanceCounter = new System.Diagnostics.PerformanceCounter();
performanceCounter.CategoryName = "Web Service";
performanceCounter.CounterName = "Current Connections";
performanceCounter.InstanceName = "SMS_Collection_CFC";
string data = string.Format("{0}\t{1} = {2}", performanceCounter.CategoryName,
performanceCounter.CounterName, performanceCounter.NextValue());
This can return the connections number.
Is this counting the TCP connections under the hood? We know there are many TCP connection status like ESTABLISHED,TIME_WAIT, which status is performance counter counting?
Since nobody answers this post, I post my findings.
In the server, I invoke the related code in the original post, and it returns 574.
string data = string.Format("{0}\t{1} = {2}", performanceCounter.CategoryName,
performanceCounter.CounterName, performanceCounter.NextValue());
And then, I run the netstat command.The website is ocupying port 9010.
netstat -an | find /i "9010"
It returens 550 established TCP connections. So I guess it is monitoring established TCP connections.
I am using SQL server 2012 at sender and receiver's service broker
and i have the following contract and message on both
create MESSAGE TYPE [//Photo/Message]
VALIDATION = NONE
create CONTRACT [//photo/Contract]
([//Photo/Message] SENT BY INITIATOR)
at sender:
create SERVICE [tcp://192.168.4.173:4022/HadoopSender/Audit/HadoopDataSender]
AUTHORIZATION dbo
ON QUEUE dbo.HadoopInitiatorAuditQueue -
i have created the route at receiver as
create ROUTE [RouteDataReceiver] WITH ADDRESS = N'TRANSPORT'
when i issue send message from sender ,it reaches target server's queue but it stays at sys.transmission_queue at sender
why this message is not deleted from sender queue sys.transmission_queue
is there any configuration that i should apply ?
because the route at receiver is transport
service at sender should be renamed as following [tcp://MachineName:PORT/UniqueServiceName]
in order to let receiver service knows which IP it should send the acknowledgment to
I have been given the task of creating a small application in VB.NET where users can enter a port number into a text field and it checks against the machines IP address to see if that port is blocked or not. I did develop a method using a TCPListener, but it seems it is not working as it needs to be. Currently i have:
Dim tcpList As TcpListener = New TcpListener(System.Net.IPAddress.Parse(Host), PortNumber)
tcpList.Start()
tcpList.Stop()
Return True
However that seems to show the Port as blocked if something is already listening in on it. Can anybody think of a way of doing this properly?
Thanks!
Try this:
If My.Computer.Network.Ping("198.01.01.01") Then
MsgBox("Server pinged successfully.")
Else
MsgBox("Ping request timed out.")
End If
Or
If My.Computer.Network.Ping("www.cohowinery.com", 1000) Then
MsgBox("Server pinged successfully.")
Else
MsgBox("Ping request timed out.")
End If
also see:https://msdn.microsoft.com/en-us/library/s9xkzk4s(v=vs.90).aspx
I have a custom Protobuf-based protocol that I've implemented as an EventMachine protocol and I'd like to use it over a secure connection between the server and clients. Each time I send a message from a client to the server, I prepend the message with a 4-byte integer representing the size of the Protobuf serialized string to be sent such that the server knows how many bytes to read off the wire before parsing the data back into a Protobuf message.
I'm calling start_tls in the post_init callback method in both the client and server protocol handlers, with the one in the server handler being passed the server's private key and certificate. There seems to be no errors happening at this stage, based on log messages I'm printing out.
Where I get into trouble is when I begin parsing data in the receive_data callback in the server's handler code... I read 4 bytes of data off the wire and unpack it to an integer, but the integer that gets unpacked is not the same integer I send from the client (i.e. I'm sending 17, but receiving 134222349).
Note that this does not happen when I don't use TLS... everything works fine if I remove the start_tls calls in both the client and server code.
Is it the case that SSL/TLS data gets passed to the receive_data callback when TLS is used? If so, how do I know when data from the client begins? I can't seem to find any example code that discusses this use case...
OK, so via a cross-post to the EventMachine Google Group I figured out what my problem was here. Essentially, I was trying to send data from the client to the server before the TLS handshake was done because I wasn't waiting until the ssl_handshake_completed callback was called.
Here's the code I got to work, just in case anyone comes across this post in the future. :)
Handler code for the server-side:
require 'eventmachine'
class ServerHandler < EM::Connection
def post_init
start_tls :private_key_file => 'server.key', :cert_chain_file => 'server.crt', :verify_peer => false
end
def receive_data(data)
puts "Received data in server: #{data}"
send_data(data)
end
end
Handler code for the client-side:
require 'eventmachine'
class ClientHandler < EM::Connection
def connection_completed
start_tls
end
def receive_data(data)
puts "Received data in client: #{data}"
end
def ssl_handshake_completed
send_data('Hello World! - 12345')
end
end
Code to start server:
EventMachine.run do
puts 'Starting server...'
EventMachine.start_server('127.0.0.1', 45123, ServerHandler)
end
Code to start client:
EventMachine.run do
puts 'Starting client...'
EventMachine.connect('127.0.0.1', 45123, ClientHandler)
end
I use C# program for client UDP application. Application listens for a connection, and then communicates.
Socket udpClient = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
udpClient.Bind(new IPEndPoint(IPAddress.Any, ListenPort));
udpClient.Blocking = true;
int count = 0;
while (count == 0) udpClient.ReceiveFrom(receiveBuffer, ref ePoint);
udpClient.SendTo(data, endPoint);
udpClient.ReceiveFrom(receiveBuffer, ref ep);
...
I use Wireshark to debug the application. The problem is that after sometime my application starts sending malformed STUN packets, and I think that because of that they get rejected by a router on the internet.
The question: is it possible to prevent sending malformed UDP/STUN packets?
When your application sends malformed UDP packets, it has a bug. The minimal fragment of your code has only one SendTo call. You can add a check function for the content/length of data.
BTW: UDP is connectionless. I would say, your application waits for a request or a kind of start command not for a connection.