9

I'm trying to write a Syslog listener and so far so good on getting it to accept incoming messages through TCP but I also want UDP to function.

This is the UDP server code I'm using, which works using a python client app. I also have another app which also works just using the python client app.

# Server program
# UDP VERSION


from socket import *

# Set the socket parameters
host = "localhost"
port = 514
buf = 1024
addr = (host,port)

# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)

# Receive messages
while 1:
    data,addr = UDPSock.recvfrom(buf)
    if not data:
        print "Client has exited!"
        break
    else:
        print "\nReceived message '", data,"'"

# Close socket
UDPSock.close()

Using this code I can send to the server and have it display the code.

# Client program

from socket import *

# Set the socket parameters
host = "localhost"
port = 514
buf = 1024
addr = (host,port)

# Create socket
UDPSock = socket(AF_INET,SOCK_DGRAM)

def_msg = "===Enter message to send to server===";
print "\n",def_msg

# Send messages
while (1):
    data = raw_input('>> ')
    if not data:
        break
    else:
        if(UDPSock.sendto(data,addr)):
            print "Sending message '",data,"'....."

# Close socket
UDPSock.close()

I have tried the Kiwi Syslog Message Generator and Snare to send syslog messages to the UDP server and nothing comes up. Could someone help me understand?

Thomas
  • 174,939
  • 50
  • 355
  • 478
Elvar
  • 444
  • 1
  • 4
  • 13
  • Are you getting a socket.error EPERM ("permission denied") in the server when binding to port 514? If not, then noting you are running as root would be useful to know. If you do not have permission denied, is some other process listening on UDP/514? `netstat -a` will tell you on unix. – msw Apr 18 '10 at 18:34
  • It runs on my Ubuntu machine on other ports than 514, syslogd probably taking port 514. But on my Windows machine it runs perfectly. – Elvar Apr 18 '10 at 20:25
  • I just tried installing the Kiwi Syslog Server to try out the client software. It does work, when I enter something in the client app the Kiwi server recieves it. – Elvar Apr 18 '10 at 21:47
  • thanks for the code snippet! the server and client are both working great for me :) – joet3ch Dec 10 '10 at 00:45
  • How can you run this code on a PC with Linux and the other with Windows7? – LEMUEL ADANE Jan 04 '13 at 02:14

1 Answers1

4

Found the problem, the code was perfect, just the Kiwi Syslog Message Generator I was using wasnt working. Along with the Kiwi Syslog Server comes an awesome probram called Log Forwarder designed to forward all sorts of event messages (way beyond what the event viewer has to offer) to a syslog server. That one also has a test feature... which works :)

Elvar
  • 444
  • 1
  • 4
  • 13