Help with sending text thou TCP/IP or LAN - vb.net

Hey all i am trying to send a text message from a virtual machine (VMWARE) to my local machine so that i can hit a button in the VM and have it do something on the local.
Is there anyway to send a text through an IP, TCP/IP, LAN using VB6 or VB.net? I was looking at the net send to send something but it doesn't seem to work for me (as well as it seems to pop up a dialog box for every text you send). I've already tried this out:
http://www.codeproject.com/KB/vb/CfSimpleSendComp.aspx
But it doesn't seem to work at all on my computer? I've tried both the IP of the machine and also the computer's name. Maybe .NET Remoting in VB?
Could anyone let me know if there are other ways to do what i would like to do?
Thanks!
David

You also can consider to use Eneter Messaging Framework.
It is lightweight and very easy to use.
I am sorry, I am not familiar with VB syntax, but in C# the whole implementation
is here: (You can copy paste the code into your project, include Eneter.Messaging.Framework.dll and change the IP to yours.)
The server listening to string messages.
using System;
using Eneter.Messaging.EndPoints.StringMessages;
using Eneter.Messaging.MessagingSystems.MessagingSystemBase;
using Eneter.Messaging.MessagingSystems.TcpMessagingSystem;
namespace StringReceiver
{
class Program
{
static void Main(string[] args)
{
// Create Tcp based messaging.
IMessagingSystemFactory aTcpMessaging = new TcpMessagingSystemFactory();
IInputChannel anInputChannel = aTcpMessaging.CreateInputChannel("127.0.0.1:7091");
// Create string message receiver
// Note: it is possible to receiver typed messages too.
IStringMessagesFactory aStringMessagesFactory = new StringMessagesFactory();
IStringMessageReceiver aStringMessageReceiver = aStringMessagesFactory.CreateStringMessageReceiver();
aStringMessageReceiver.MessageReceived += StringMessageReceived;
// Attach the input channel to the string message receiver
// and start listening.
Console.WriteLine("String sercer is listening.");
aStringMessageReceiver.AttachInputChannel(anInputChannel);
}
// Processing messages.
static void StringMessageReceived(object sender, StringMessageEventArgs e)
{
Console.WriteLine("Received message: " + e.Message);
}
}
}
The client sending the string messages:
using Eneter.Messaging.EndPoints.StringMessages;
using Eneter.Messaging.MessagingSystems.MessagingSystemBase;
using Eneter.Messaging.MessagingSystems.TcpMessagingSystem;
namespace StringMessageSender
{
class Program
{
static void Main(string[] args)
{
// Create Tcp based messaging.
IMessagingSystemFactory aTcpMessaging = new TcpMessagingSystemFactory();
IOutputChannel anOutputChannel = aTcpMessaging.CreateOutputChannel("127.0.0.1:7091");
// Create string message receiver
// Note: it is possible to receiver typed messages too.
IStringMessagesFactory aStringMessagesFactory = new StringMessagesFactory();
IStringMessageSender aStringMessageSender = aStringMessagesFactory.CreateStringMessageSender();
// Attach the output channel to the string message sender
// so that we can send messages via Tcp to desired Ip address.
aStringMessageSender.AttachOutputChannel(anOutputChannel);
// Send message.
aStringMessageSender.SendMessage("Hello world.");
}
}
}
Eneter Messaging Framework can be downloaded at www.eneter.net.
If you would like to get more technical info: www.eneter.net/OnlineHelp/EneterMessagingFramework/Index.html
More examples: eneter.blogspot.com

You need a client and a server, one of them at each end. These could communicate over TCPIP (TCP or UDP), Microsoft Networking (named Pipes, Mailslots), or whatever you have. Some options depend on what OS the two machines are running, but since you mentioned NET SEND we can probably assume some flavor of Windows.
The Messenger Service is gone in later versions of Windows NT (Vista, Windows 7) so it's not the best option. There are other Mailslots messengers though as well as lots of UDP messengers.
The real question is what action you want to perform "at the push of a button." Heck, you could easily run Telnet if that gave you what you were after.
Don't forget you may have to open firewalls for any of these to work though.
.Net Remoting isn't available in VB, you must mean VB.Net. That's a remote object invokation technology though and probably not what you want.
You'd probably get to a result more quickly picking one development tool set and using whatever it offers for TCP or UDP sockets.

There are several ways. The best way depends on how you define 'text message'.
If you literally just need to hit a button and run a command on a remote machine, I would run PsExec in Process object. Cheesy but effective. Something like:
Using p as new Process()
p.StartInfo.FileName = "c:\path\to\PsExec.exe"
p.StartInfo.Arguments = "\\RemoteComputerName RemoteCommand.exe"
p.Start()
End Using
If you need bi-directional communication with a custom protocol, I would use WCF or the TCPListener and TCPClient classes to create your own socket server and client.
I would stay away from remoting.

Related

Sending ethernet frames from kernel module

I have a kernel module that would like to send pre-fabricated ethernet frames from user space such as custom ARP, and other protocols (I'm trying to bypass tcp/ip stack on linux and create custom one for my needs). Frames are valid and complete with all necessary things. The only part that remains is to send them somehow to the queue on eth0 interface. What is the best solution to do this?
For snatching incoming packets I am using netfilter API with the earliest hook possible. I can not use raw sockets from user space due to the need of sudo and also due to my custom requirements.
Edit: I was able to achieve my goals with dev_queue_xmit(). However, I am still wondering if there is another solution that accesses the driver directly.
static void SendFrame(void)
{
struct sk_buff* skb = dev_alloc_skb(1518);
skb->dev = __dev_get_by_name(&init_net, "eth0");
skb_reserve(skb, NET_IP_ALIGN);
skb->data = skb_put(skb, ethFrameBytes);
memcpy(skb->data, pEthFrame, ethFrameBytes);
if (dev_queue_xmit(skb) != NET_XMIT_SUCCESS)
{
printk(KERN_ERR, KERN_ERR "Error: unable to send the frame\n");
}
}

MarshalByRefObject causing C++ program to hang

I have a client program that uses a MarshalByRefObject to get a variable from a remote server. Sometimes the program hoses up on the remote server and when I try to get that variable my client program simply hangs. Is there a way to time out the call on this variable?
MyClass^ refObject = (MyClass^)System::Activator::GetObject(MyClass::typeid, url);
THEVARIABLE objectVariable = refObject->theVariable;
The only way I see is to implement an IMessageFilter (COM). In some cases it is possible to detect that there is an out of process call from the current STA to another. But AFAIK this is only done when an input message (keyboard/mouse) arrives.
With a message filter you can show something like "waiting for external com call...". Also in this case you may abort the external call.
See CoRegisterMessageFilter, and IMessageFilter

Which ServiceControl.Contracts messages should IHandle?

I'm trying to make sure that 3rd party dependencies are running, and built a service to do this based on the Monitoring 3rd party Sample Application, which emits ServiceControl CheckResult messages.
This works fine; ServicePulse alerts me when I stop/start my local and remote windows services, Databases, Flux Capacitors, etc.
I now want to build a windows service / nServiceBus Endpoint, like ServicePulse, but with logic that can attempt recovery, send emails etc. I don't really want to put this code into the 3rdParty monitor.
I followed the servicecontrol/external-integrations and servicecontrol/contracts tutorials, and created my MendStuffOrEmail endpoint - But it doesn't work; It doesn't receive any messages.
I was going to ask "what am I doing wrong?", but I think I know; I'm using IHandleMessages<ServiceControl.Contracts.MessageFailed> which is for failed messages.
I need to listen for the "CheckResult" type messages - but what are they? I have looked through the ServiceControl and ServicePulse code, but cannot work out what is being sent/received. How can I find this out, or has anyone else actually done this and already knows?
UPDATE
After more extensive rummaging, I also subscribed to CustomCheckFailed and CustomCheckSucceeded messages. I implemented IHandle interfaces for them, but I'm still not getting any messages. The log shows autosubscriber has taken out a subscription to them. What should I check for next?
I compared my code to Sean's posted
example and found the mistake:
I had implemented two of the interfaces, IConfigureThisEndpoint and AsA_Server in the wrong class (a 2am cut 'n' paste error).
The example listens for failed messages, but for anyone else trying to do this, you do need to subscribe to CustomCheckFailed and CustomCheckSucceeded messages (nuget ServiceControl.Contracts).
public partial class MessageHandler : IHandleMessages<CustomCheckFailed>,
IHandleMessages<CustomCheckSucceeded>
{
public void Handle(CustomCheckFailed message)
{
this.HandleImplementation(message);
}
partial void HandleImplementation(CustomCheckFailed message);
public void Handle(CustomCheckSucceeded message)
{
this.HandleImplementation(message);
}
partial void HandleImplementation(CustomCheckSucceeded message);
public IBus Bus { get; set; }
}
then the logic to do something with the messages. (I left in my original test - sending email - but our system has a library with all sorts of recovery & notification methods. You'll need something similar to stop an email flood):
public partial class MessageHandler
{
partial void HandleImplementation(CustomCheckFailed message)
{
var messageBody = string.Format("Message with id {0} failed with reason {1}", message.CustomCheckId, message.FailureReason);
MailMessageFactory.sendEmail("Failure Notification", messageBody);
Console.Out.WriteLine(messageBody);
}
}
And a similar file with the logic for recovery messages (CustomCheckSucceeded). You probably want a check in there to detect it is actually recovering from a failure, not just passing the test.
So anyway, fixed - on my dev pc.
The next problem was making it work on the server, which took a support call. It turns out ServiceControl ALSO needs a licence, available as part of the "Advanced", "Enterprise", and "Ultimate" editions - Not part of the platform on the standard licence.

How can I use the Error Handler to reconnect to the redistribution server in StackServices.RedisMqServer?

I'm using a queue to direct the service error events, but if the redistribution server fails, I need the queue to try to connect itself to the redistribution server, at least 2 more times after the exception is thrown.
I am trying to use the RetryCount property, but it doesn't seem to work. Is there any other way to try to reconnect to the redistribution server through ErrorHandler?
I suppose, I don't know Spanish, neither I use Redis,
reading only the documentation ServiceStack RedisMqServer
this is the initialization, where you set the retryCount .
var redisFactory = new PooledRedisClientManager("localhost:6379");
var mqHost = new RedisMqServer(redisFactory, retryCount:2);
but the RetryCount, is protected (set)
public int RetryCount { get; protected set; }
So I think it is not possible to reset it.
I don't know about another way to "re-attempt to connect to the server via ErrorHandler "
I gave it a try
BTW I cannot find the source in github for RedisMqServer in ServiceStack v3.
During the last changes, it seems the link is broken.

Windows 8 Socket communication with Background Task

I have a Background Task written in C# in a Windows 8 App, and I'm having trouble connecting it to my UI task. I've tried opening a StreamSocketListener on my background task and a StreamSocket to connect to it on my UI task, as well as the other way around. If I have both the listener and the connector in the UI task, or the background task, everything works fine. However, there seems to be some kind of isolation enforced between the two of them.
I can also connect out to external services on both of them, so I thought it might have something to do with needing a loopback exemption, but that doesn't seem to be the case either, as opening up the AppContainer Loopback Exemption Utility shows all apps as having loopback access.
Is there something else I need to enable to get network communication between these two parts of my app working properly? I have enabled the Private Networks (Client and Server) capabilities in my package manifest, (the other client/server pairs don't help, so i'm just using that one)
You could use the completion event of your background task and run it repeatedly in your UI. Using LocalSettings to pass data.
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh977055.aspx
private void OnCompleted(IBackgroundTaskRegistration task, BackgroundTaskCompletedEventArgs args)
{
var settings = ApplicationData.Current.LocalSettings;
var key = task.TaskId.ToString();
var message = settings.Values[key].ToString();
UpdateUIExampleMethod(message);
}