|
Andy202 wrote: If I comment out the receive I get error 10057 on the send.
The error is WSAENOTCONN.
That's expected since you're using the "from" address from the recvfrom(),
which isn't going to be a valid address without a successful recvfrom() call.
Andy202 wrote: I would like my UDP server to send the data when the client connects;
UDP is connectionless so you don't know if a client is connected or not.
It sounds like you need to either...
1) Keep track of clients that are listening - that would mean a client has to send a notification to
the server when it's ready to receive datagrams. The server can store a list of "connected" clients and
send the periodic datagrams to every address on the list.
2) Broadcast the periodic datagrams. Set the socket option SO_BROADCAST on the socket and send
to the broadcast address (INADDR_BROADCAST). The clients need to set the SO_BROADCAST socket option
as well.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks again for your Post Mark, I now get Error = 10057 when the Client is not running and Error = 10093 when the Client is running.
local.sin_family = AF_INET;<br />
local.sin_addr.s_addr = INADDR_BROADCAST;<br />
local.sin_port = htons(port);<br />
<br />
conn_socket = socket(AF_INET, socket_type, 0); <br />
<br />
if (setsockopt (conn_socket, SOL_SOCKET, SO_BROADCAST, (char *) &TxBuffer, sizeof (TxBuffer)) == SOCKET_ERROR)<br />
{<br />
closesocket (conn_socket);<br />
g_szFormatting.Format("setsockopt() failed: %d\n",WSAGetLastError());<br />
ReportMessages(g_szFormatting);<br />
WSACleanup();<br />
return false;<br />
}<br />
<br />
if (setsockopt (conn_socket, SOL_SOCKET, SO_REUSEADDR , (char *) &optval, sizeof(optval)) == SOCKET_ERROR)<br />
{ <br />
g_szFormatting.Format("Couldn't set SO_REUSEADDR %d\n ", WSAGetLastError());<br />
ReportMessages(g_szFormatting);<br />
closesocket (conn_socket);<br />
WSACleanup();<br />
return false;<br />
}
And in the Writer Thread:-
while(g_bUDP_Socket_Created && g_bUDPStatus)<br />
{<br />
<br />
retval = sendto (conn_socket, (char*)TxBuffer, sizeof(Tx_Data), 0, NULL , 0);<br />
if (retval == SOCKET_ERROR)<br />
{ <br />
g_szFormatting.Format("Couldn't send data, %d",WSAGetLastError());<br />
::MessageBox((HWND)NULL,g_szFormatting, NULL,MB_ICONEXCLAMATION );<br />
closesocket (conn_socket);<br />
WSACleanup();<br />
}<br />
Sleep(1000);<br />
}<br />
closesocket(conn_socket);<br />
WSACleanup();
|
|
|
|
|
Error 10093 WSANOTINITIALISED Successful WSAStartup not yet performed
Also...
You need to create a proper UDP socket:
conn_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP
); <br />
<br /> and sendto() needs a destination address.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
One final question Mark, if I just want to Broadcast UDP packets out on a local network, what destination address do I use?
|
|
|
|
|
Andy202 wrote: I just want to Broadcast UDP packets out on a local network, what destination address do I use
You could use the limited broadcast address 255.255.255.255 , however it is best to use the correct IP broadcast address of your local network segment (more successful in my own experience). You can calculate the correct broadcast address, see here.
/M
|
|
|
|
|
Hi,
I need any sample..code or advice for usb communication in MFC.
I need to do read and write operations on a usb device..
thanks in advance
Ashok
|
|
|
|
|
Which kind of device are you communicating with ? USB doesn't work like a serial port: you don't have access directly to the port but instead you get the handle of a driver. This driver is shipped with the device you want to communicate with and manages all the communication with the device.
To get the handle of the driver, simply call CreateFile supplying the correct driver name, then you should be able to use ReadFile and WriteFile. You can also do some more specific stuff by calling DeviceIOControl (in which you can pass some specific IO code which is dependent of your driver).
So, if you want more help, you'll need to give a lot more information (which device do you try to access, if you have documentation with it, ...).
|
|
|
|
|
can anybody help me make a program that can do any of these numerical method?
moss,newton method, secant method, taylor-maclauren,bisection method,gaussian elimination, gauss-seindal,lagrange method.
thanks guys!!
|
|
|
|
|
homework?
don't tell me that you don't find the way to implement the secant-method or bisection method !
You have only to implement the algorithm:
ask for a function f(x) and for the borders x1 and x2.
check that sign(f(x1)) != sign(f(x2)) .
Then compute x3 inside the interval (x1, x2). This according on the algorithm, in bisection case x3=(x1+x2)/2,....in secant method it's only the point where the line from (x1,f(x1)) to (x2,f(x2)) intercept the x-axe.
then choose the new interval (or x1-x3 or x3-x2) according on where is the root.
Then start again on the new interval.
Do this 10000...000 times and stop it. Or stop when the interval is "too small".
That's it.
Russell
|
|
|
|
|
thanks russell!
it a project actually..
|
|
|
|
|
ok, you convinced me.;)
Then you won this link[^].
(the routines are in C, not in C++. but it is easy to translate they)
Russell
|
|
|
|
|
thanks for the link that's really helpful.
|
|
|
|
|
mitsui58 wrote: can anybody help me make a program that can do any of these numerical method?
Yes, I'm sure someone can.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
you can use the GNU scientific library.
It will give your the needed method.
|
|
|
|
|
Can any one suggest me some ways to monitor the cts pin of the serial port using DCB.
S.Yamini
|
|
|
|
|
i have worked very enough with serial port(RS 232).
but never heard of the cts pin and dcb.
atleast for my information please educate me regarding those.
then i will try to solve if it in my perview.
thanku.
|
|
|
|
|
I am using vc++ 6.0 for serial port communication. dcb is structure defines the control setting for a serial communications device.
I have to monitor the cts (Clear to send)pin of the serial port.
S.Yamini
|
|
|
|
|
I use PCOMM library for sending and receiving data using serial port.
functions are like
sio_ioctl(); to define the port settings.
sio_read();
sio_write();
soi_iqueue();to find weather any data is there in the port.
may be i can help you if you are also using these libraries and functions.
|
|
|
|
|
yaminisridaran wrote: Can any one suggest me some ways to monitor the cts pin of the serial port using DCB.
i think u need to set fOutxCtsFlow flag of the DCB to TRUE to monitor the CTS signal.
"Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"
|
|
|
|
|
I have set fOutxCtsFlow to true but it is always true even if the voltage level in cts pin changes.
S.Yamini
|
|
|
|
|
|
I already using GetCommState.
My Code
CString strPort;
strPort.Format("COM%d:",1);
m_hPort=CreateFile(strPort,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
if(m_hPort==INVALID_HANDLE_VALUE)
{
return false;
}
GetCommState(m_hPort,&dcb);
BOOL res;
dcb.fOutxCtsFlow=true;
res=SetCommState(m_hPort,&dcb);
// Configure serial port
GetCommState(m_hPort,&dcb);
if(dcb.fOutxCtsFlow==TRUE)
TRACE("TURNED OFF");
else if(dcb.fOutxCtsFlow==FALSE)
{
TRACE("TURNED ON");
}
dcb.fOutxCtsFlow is always true even the voltage level changes
S.Yamini
|
|
|
|
|
Did you read my message ? Where do I speak about GetCommState ? I even gave you the link to the documentation, did you have a look at them ?
|
|
|
|
|
Hey guys,
I develop applications using MFC and Visual C++ 6 and I am working on a particular application that needs to access data over the internet.
Can I do this using the MFC Framework or am I better just biting the bullet and get myself up to speed with Visual C# 2005?
Best Regards
Danny Nowlan
|
|
|
|
|