Don't comment the topic if you have a new question.
You can create a new topic selecting correct category from Gurux Forum and then create a new topic selecting "New Topic" from the top left.
By max, 13 June, 2014
Hi
I have see Udp in your code. The net is support UDP?
I was see some strange code. It is configure to ProtocolType,Tcp. Could you please check code as below.
else if (m_Protocol == NetworkType.Udp)
{
if (!IsVirtual)
{
m_Socket = new Socket(family, SocketType.Stream, ProtocolType.Tcp);
}
}
Hi
I have try to upgrade V7.0.23.1 and configure udp by construe. The send Method has some exception. It has not working at "socketEventArg.RemoteEndPoint = m_Socket.RemoteEndPoint;".
Do you think it need to modify non-sync transfer data for UDP?
or Do you kindly to provide some UDP non-sync example code for Gurux.NET?
public void Send(object data, string receiver)
{
if (m_Socket == null && !VirtualOpen)
{
throw new Exception(Resources.InvalidConnection);
}
if (!this.m_Server)
{
byte[] value = Gurux.Common.GXCommon.GetAsByteArray(data);
if (m_Trace == TraceLevel.Verbose && m_OnTrace != null)
{
m_OnTrace(this, new TraceEventArgs(TraceTypes.Sent, value, receiver));
}
//Reset last position if Eop is used.
lock (m_syncBase.m_ReceivedSync)
{
m_syncBase.m_LastPosition = 0;
}
if (!IsVirtual)
{
// Create SocketAsyncEventArgs context object
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
SocketError err = 0;
try
{
// Set properties on context object
socketEventArg.RemoteEndPoint = m_Socket.RemoteEndPoint;
socketEventArg.UserToken = null;
// Inline event handler for the Completed event.
// Note: This event handler was implemented inline in order to make this method self-contained.
socketEventArg.Completed += new EventHandler(delegate(object s, SocketAsyncEventArgs e)
{
err = e.SocketError;
m_clientDone.Set();
});
socketEventArg.SetBuffer(value, 0, value.Length);
// Sets the state of the event to nonsignaled, causing threads to block
m_clientDone.Reset();
// Make an asynchronous Send request over the socket
m_Socket.SendAsync(socketEventArg);
// Block the UI thread for a maximum of TIMEOUT_MILLISECONDS milliseconds.
// If no response comes back within this time then proceed
m_clientDone.WaitOne(TIMEOUT_MILLISECONDS);
}
finally
{
socketEventArg.Dispose();
}
if (err != 0)
{
throw new SocketException((int)err);
}
}
else
{
m_OnDataSend(this, new ReceiveEventArgs(data, receiver));
}
this.m_BytesSend += (ulong)value.Length;
}
else
{
#if !WINDOWS_PHONE
Socket client = null;
foreach (var it in m_ServerDataBuffers)
{
if (it.Key.RemoteEndPoint.ToString() == receiver)
{
client = it.Key;
break;
}
}
if (client == null)
{
throw new Exception(Resources.InvalidClient);
}
byte[] value = Gurux.Common.GXCommon.GetAsByteArray(data);
client.Send(value);
this.m_BytesSend += (ulong)value.Length;
#endif
}
}
UDP issue
Hi Max,
You are right. We fixed it and updated new code to GitHub and nuget.org
Version is 7.0.23.1
BR,
Mikko
How to configure UDP?
Hi Mikko,
I also have UDP related question.
Is that how to configure UDP setting in DLMS director?
Seems that I do not find any column in UI. Do I miss anythings?
Thanks for answer
BR,
Marcus
Hi I have try to upgrade
Hi
I have try to upgrade V7.0.23.1 and configure udp by construe. The send Method has some exception. It has not working at "socketEventArg.RemoteEndPoint = m_Socket.RemoteEndPoint;".
Do you think it need to modify non-sync transfer data for UDP?
or Do you kindly to provide some UDP non-sync example code for Gurux.NET?
public void Send(object data, string receiver)(delegate(object s, SocketAsyncEventArgs e)
{
if (m_Socket == null && !VirtualOpen)
{
throw new Exception(Resources.InvalidConnection);
}
if (!this.m_Server)
{
byte[] value = Gurux.Common.GXCommon.GetAsByteArray(data);
if (m_Trace == TraceLevel.Verbose && m_OnTrace != null)
{
m_OnTrace(this, new TraceEventArgs(TraceTypes.Sent, value, receiver));
}
//Reset last position if Eop is used.
lock (m_syncBase.m_ReceivedSync)
{
m_syncBase.m_LastPosition = 0;
}
if (!IsVirtual)
{
// Create SocketAsyncEventArgs context object
SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
SocketError err = 0;
try
{
// Set properties on context object
socketEventArg.RemoteEndPoint = m_Socket.RemoteEndPoint;
socketEventArg.UserToken = null;
// Inline event handler for the Completed event.
// Note: This event handler was implemented inline in order to make this method self-contained.
socketEventArg.Completed += new EventHandler
{
err = e.SocketError;
m_clientDone.Set();
});
socketEventArg.SetBuffer(value, 0, value.Length);
// Sets the state of the event to nonsignaled, causing threads to block
m_clientDone.Reset();
// Make an asynchronous Send request over the socket
m_Socket.SendAsync(socketEventArg);
// Block the UI thread for a maximum of TIMEOUT_MILLISECONDS milliseconds.
// If no response comes back within this time then proceed
m_clientDone.WaitOne(TIMEOUT_MILLISECONDS);
}
finally
{
socketEventArg.Dispose();
}
if (err != 0)
{
throw new SocketException((int)err);
}
}
else
{
m_OnDataSend(this, new ReceiveEventArgs(data, receiver));
}
this.m_BytesSend += (ulong)value.Length;
}
else
{
#if !WINDOWS_PHONE
Socket client = null;
foreach (var it in m_ServerDataBuffers)
{
if (it.Key.RemoteEndPoint.ToString() == receiver)
{
client = it.Key;
break;
}
}
if (client == null)
{
throw new Exception(Resources.InvalidClient);
}
byte[] value = Gurux.Common.GXCommon.GetAsByteArray(data);
client.Send(value);
this.m_BytesSend += (ulong)value.Length;
#endif
}
}
How to configure UDP
Hi,
We do not have any meters that are using UDP.
All meters are using TCP/IP. :-)
We will made UDP test meter and try to solve your problem.
BR,
Mikko