<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>C Board - Networking/Device Communication</title>
		<link>http://cboard.cprogramming.com</link>
		<description>Networking and external device communication questions</description>
		<language>en</language>
		<lastBuildDate>Sat, 21 Nov 2009 00:23:18 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://cboard.cprogramming.com/images/misc/rss.jpg</url>
			<title>C Board - Networking/Device Communication</title>
			<link>http://cboard.cprogramming.com</link>
		</image>
		<item>
			<title>Client Server User registration and logon</title>
			<link>http://cboard.cprogramming.com/networking-device-communication/121736-client-server-user-registration-logon.html</link>
			<pubDate>Wed, 18 Nov 2009 17:55:03 GMT</pubDate>
			<description>I now have a functioning client server style chat written in C. However, the next part of functionality includes the ability for users to register themselves a user name and password and then be able to use these in the future. 
 
Can anyone give me any hints to get me started? 
 
 Obviously the...</description>
			<content:encoded><![CDATA[<div>I now have a functioning client server style chat written in C. However, the next part of functionality includes the ability for users to register themselves a user name and password and then be able to use these in the future.<br />
<br />
Can anyone give me any hints to get me started?<br />
<br />
 Obviously the socket will have to be setup before this can take place so somehow the server has to recognize a login attempt and deal with it.</div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/networking-device-communication/">Networking/Device Communication</category>
			<dc:creator>Martin_T</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/networking-device-communication/121736-client-server-user-registration-logon.html</guid>
		</item>
		<item>
			<title><![CDATA[[Win32] Wrapping in_addr in a class]]></title>
			<link>http://cboard.cprogramming.com/networking-device-communication/121733-%5Bwin32%5D-wrapping-in_addr-class.html</link>
			<pubDate>Wed, 18 Nov 2009 15:54:20 GMT</pubDate>
			<description><![CDATA[I'm trying to make a neat wrapper that wraps the IP address structures. However, I'm grappling with how to make the class both IPv4 and IPv6 friendly. Can anyone provide any resources (code snippets, links, etc) that can shed some light on how I may approach my design? 
 
Thanks!]]></description>
			<content:encoded><![CDATA[<div>I'm trying to make a neat wrapper that wraps the IP address structures. However, I'm grappling with how to make the class both IPv4 and IPv6 friendly. Can anyone provide any resources (code snippets, links, etc) that can shed some light on how I may approach my design?<br />
<br />
Thanks!</div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/networking-device-communication/">Networking/Device Communication</category>
			<dc:creator>Mastadex</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/networking-device-communication/121733-%5Bwin32%5D-wrapping-in_addr-class.html</guid>
		</item>
		<item>
			<title>socket send</title>
			<link>http://cboard.cprogramming.com/networking-device-communication/121731-socket-send.html</link>
			<pubDate>Wed, 18 Nov 2009 14:25:03 GMT</pubDate>
			<description><![CDATA[I got a little problem with a server / client, using TCP. 
 
If I start my server, then start my client, all is good. 
My client and server finds out if they "Loose connection", by checking returnvalue of recv(). 
 
But some of the functionality in my client use send() only, before any recv()....]]></description>
			<content:encoded><![CDATA[<div>I got a little problem with a server / client, using TCP.<br />
<br />
If I start my server, then start my client, all is good.<br />
My client and server finds out if they &quot;Loose connection&quot;, by checking returnvalue of recv().<br />
<br />
But some of the functionality in my client use send() only, before any recv().<br />
Meaning if I start my server, start my client, close the server, then my client will do send() to a closed connection.... And then I get segmentationFault.<br />
<br />
How to avoid this?</div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/networking-device-communication/">Networking/Device Communication</category>
			<dc:creator>Drogin</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/networking-device-communication/121731-socket-send.html</guid>
		</item>
		<item>
			<title>Problem with client</title>
			<link>http://cboard.cprogramming.com/networking-device-communication/121223-problem-client.html</link>
			<pubDate>Mon, 02 Nov 2009 14:02:28 GMT</pubDate>
			<description><![CDATA[Hello, 
I´ve programmed a chatprogram, but the client doesn't connect to the server. 
I'm in a local Network. But when someone from outside this network want to connect to 
my computer it doesn't work. Here are the sources from the server and the client: 
 
Client : 
 
Code: 
--------- 
#include...]]></description>
			<content:encoded><![CDATA[<div>Hello,<br />
I´ve programmed a chatprogram, but the client doesn't connect to the server.<br />
I'm in a local Network. But when someone from outside this network want to connect to<br />
my computer it doesn't work. Here are the sources from the server and the client:<br />
<br />
Client :<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">#include &lt;windows.h&gt;<br />
#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
#include &lt;string.h&gt;<br />
#include &lt;winsock.h&gt;<br />
#include &quot;resource.h&quot;<br />
<br />
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);<br />
<br />
int i;<br />
char ip[20];<br />
char version[] = {&quot;Senden&quot;};<br />
FILE *f;<br />
WSADATA wsa;<br />
int s;<br />
int senden;<br />
struct sockaddr_in addr;<br />
char text[75];<br />
char own_name[60];<br />
char name[60];<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
LPCSTR lpszAppName = version;<br />
LPCSTR lpszTitle&nbsp;  = version;<br />
<br />
HINSTANCE hInst;<br />
<br />
int APIENTRY WinMain(HINSTANCE hInstance,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)<br />
{<br />
&nbsp;  HWND&nbsp; &nbsp; &nbsp;  hWnd, bButton, hList;<br />
&nbsp;  MSG&nbsp; &nbsp; &nbsp; &nbsp; msg;<br />
&nbsp;  WNDCLASSEX&nbsp;  wc;<br />
<br />
&nbsp;  wc.cbSize&nbsp; &nbsp; &nbsp; &nbsp; =&nbsp; sizeof(WNDCLASSEX);<br />
&nbsp;  wc.style&nbsp; &nbsp; &nbsp; &nbsp;  =&nbsp; CS_HREDRAW | CS_VREDRAW;<br />
&nbsp;  wc.lpfnWndProc&nbsp;  =&nbsp; WndProc;<br />
&nbsp;  wc.cbClsExtra&nbsp; &nbsp; =&nbsp; 0;<br />
&nbsp;  wc.cbWndExtra&nbsp; &nbsp; =&nbsp; 0;<br />
&nbsp;  wc.hInstance&nbsp; &nbsp;  =&nbsp; hInstance;<br />
&nbsp;  wc.hCursor&nbsp; &nbsp; &nbsp;  =&nbsp; LoadCursor(NULL,IDC_ARROW);<br />
&nbsp;  wc.hIcon&nbsp; &nbsp; &nbsp; &nbsp;  =&nbsp; LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_APPLICATION));<br />
&nbsp;  wc.hbrBackground =&nbsp; GetStockObject(DKGRAY_BRUSH);<br />
&nbsp;  wc.lpszClassName =&nbsp; lpszAppName;<br />
&nbsp;  wc.lpszMenuName&nbsp; =&nbsp; NULL;<br />
&nbsp;  wc.hIconSm&nbsp; &nbsp; &nbsp;  =&nbsp; (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_APPLICATION), IMAGE_ICON, 16, 16, 0);<br />
<br />
&nbsp;  if( RegisterClassEx(&amp;wc) == 0)<br />
&nbsp; &nbsp; &nbsp; return 0;<br />
&nbsp; &nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp;  hInst=hInstance;<br />
&nbsp;  <br />
hWnd = CreateWindowEx(NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  lpszAppName,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  lpszTitle,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  WS_OVERLAPPEDWINDOW,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  200,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  200,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  400,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  100,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  NULL,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  hInstance,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  NULL);<br />
<br />
bButton = CreateWindow(&quot;BUTTON&quot;,&quot;Senden&quot;,WS_CHILD|WS_VISIBLE|<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BS_DEFPUSHBUTTON, 140, 40, 100, 20,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hWnd, (HMENU)BUTTON, hInstance, NULL);<br />
<br />
&nbsp;  if( hWnd == NULL)<br />
&nbsp; &nbsp; &nbsp; return 0;<br />
<br />
&nbsp;  ShowWindow(hWnd, iCmdShow);<br />
&nbsp;  UpdateWindow(hWnd);<br />
<br />
&nbsp;  while (GetMessage(&amp;msg, NULL, 0, 0))<br />
&nbsp;  {<br />
&nbsp; &nbsp; &nbsp; TranslateMessage(&amp;msg);<br />
&nbsp; &nbsp; &nbsp; DispatchMessage(&amp;msg);<br />
&nbsp;  }<br />
<br />
<br />
&nbsp;  return msg.wParam;<br />
}<br />
<br />
&nbsp; &nbsp; &nbsp; <br />
<br />
LRESULT CALLBACK WndProc(HWND hWnd, UINT umsg, WPARAM wParam, LPARAM lParam)<br />
{&nbsp; &nbsp; <br />
&nbsp;  HWND hEdit; <br />
&nbsp;  <br />
&nbsp;  switch (umsg)<br />
&nbsp;  {&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case WM_CREATE:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, &quot;EDIT&quot;, &quot;&quot;, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WS_CHILD | WS_VISIBLE , <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 10, 10, 368, 20, hWnd, (HMENU)IDC_EDIT, GetModuleHandle(NULL), NULL);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SendMessage(hEdit, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case WM_DESTROY:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  remove(&quot;send&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  PostQuitMessage(0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  return 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; case WM_COMMAND :<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; switch( LOWORD( wParam ) )<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; case BUTTON:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memset(ip, 0, sizeof(ip));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Socket wird vorbereitet<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f = fopen(&quot;own_name&quot;, &quot;r&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while( fgets(name, sizeof(name), f) !=0 )<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fclose(f);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy(own_name, &quot;_&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcat(own_name, name);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f = fopen(&quot;send&quot;, &quot;r&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fgets(ip, sizeof(ip), f);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fclose(f);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox(NULL,ip,&quot;TEST&quot;,MB_OK);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addr.sin_family = AF_INET;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addr.sin_port = htons(7700);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addr.sin_addr.s_addr = inet_addr( ip );<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox(NULL,ip,&quot;TEST&quot;,MB_OK);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (WSAStartup(MAKEWORD(1, 1), &amp;wsa))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MessageBox(NULL,&quot;WSAStartup() failed!&quot;,&quot;ERROR&quot;,MB_OK | MB_ICONERROR);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s = socket(AF_INET,SOCK_STREAM,0);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (connect(s, (struct sockaddr*) &amp;addr, sizeof(addr)) &lt; 0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  MessageBox(NULL, &quot;Fehler beim Senden!&quot;, &quot;ERROR&quot;,MB_OK | MB_ICONERROR);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GetDlgItemText( hWnd, IDC_EDIT, text, sizeof(text) -15);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcat(text, own_name);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; senden = send(s, text, strlen(text), 0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closesocket(s);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PostQuitMessage(0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; break;<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp;  }<br />
&nbsp;  return DefWindowProc(hWnd, umsg, wParam, lParam);<br />
}</code><hr />
</div><br />
<br />
<br />
Server:<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">#include &lt;stdio.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
#include &lt;string.h&gt;<br />
#include &lt;windows.h&gt;<br />
#include &lt;mmsystem.h&gt;<br />
#include &lt;winsock.h&gt;<br />
<br />
int main(int argc, char *argv[])<br />
{<br />
&nbsp; &nbsp; &nbsp; &nbsp; WSADATA wsa;<br />
&nbsp; &nbsp; &nbsp; &nbsp; char user_name[60];<br />
&nbsp; &nbsp; &nbsp; &nbsp; int i = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; int j = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; int s;<br />
&nbsp; &nbsp; &nbsp; &nbsp; int c;<br />
&nbsp; &nbsp; &nbsp; &nbsp; int empfangen;<br />
&nbsp; &nbsp; &nbsp; &nbsp; char text[75];<br />
&nbsp; &nbsp; &nbsp; &nbsp; char message[75];<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  struct sockaddr_in cli;<br />
&nbsp; &nbsp; &nbsp; &nbsp; int cli_size;<br />
&nbsp; &nbsp; &nbsp; &nbsp; struct sockaddr_in addr;<br />
&nbsp; &nbsp; &nbsp; &nbsp; FILE * f;<br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (WSAStartup(MAKEWORD(1, 1), &amp;wsa))<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;WSAStartup() failed, %lu\n&quot;, (unsigned long)GetLastError());<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return EXIT_FAILURE;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; s = socket(AF_INET,SOCK_STREAM,0);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; memset( &amp;addr, 0, sizeof (addr));<br />
&nbsp; &nbsp; &nbsp; &nbsp; addr.sin_family = AF_INET;<br />
&nbsp; &nbsp; &nbsp; &nbsp; addr.sin_port = htons(7700);<br />
&nbsp; &nbsp; &nbsp; &nbsp; addr.sin_addr.s_addr = htonl( INADDR_ANY );<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (bind(s, (struct sockaddr*) &amp;addr, sizeof(addr)) == -1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; perror(&quot;bind() failed&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (listen(s, 3) == -1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; perror(&quot;listen () failed&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; for(;;)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cli_size = sizeof(cli);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c = accept(s, (struct sockaddr*) &amp;cli, &amp;cli_size);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;Verbindung von %s\n&quot;, inet_ntoa(cli.sin_addr));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; empfangen = recv(c, text, sizeof(text) - 1, 0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PlaySound(&quot;neue_nachricht.wav&quot;,NULL,SND_FILENAME);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (empfangen &gt; 0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text[empfangen] = '\0';<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcpy(message, text);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = sizeof(message);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ( message[i] != 95)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message[i] = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i--;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; message[i] = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while( text[i] != 95)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ( text[i] != 0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user_name[j] = text[i];<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; j++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcat(user_name, &quot; (&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcat(user_name, inet_ntoa(cli.sin_addr));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strcat(user_name, &quot;)&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f = fopen(&quot;usr&quot;, &quot;w&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fputs(user_name, f);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fclose(f);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; f = fopen(&quot;msg&quot;, &quot;w&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fputs(message,f);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fclose(f);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while( user_name[i] != sizeof(user_name))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  user_name[i] = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  i++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  i = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  j = 0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;Fehler beim lesen\n&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; closesocket(c);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; closesocket(s);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; getchar();<br />
&nbsp; &nbsp; &nbsp; &nbsp; return 0;<br />
}</code><hr />
</div>I hope someone can help me.<br />
<br />
<br />
PS: I am from Germany so my english is not perfect!</div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/networking-device-communication/">Networking/Device Communication</category>
			<dc:creator>Dave007</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/networking-device-communication/121223-problem-client.html</guid>
		</item>
		<item>
			<title>Using ip tables to forward port to virtual machine</title>
			<link>http://cboard.cprogramming.com/networking-device-communication/121135-using-ip-tables-forward-port-virtual-machine.html</link>
			<pubDate>Fri, 30 Oct 2009 17:50:24 GMT</pubDate>
			<description><![CDATA[I'm running VirtualBox for a class lab, and VirtualBox on Ubuntu appears to be missing the "Bridge Interface" feature for a network adapter - so the instructions we were given won't work for me, and the TA's don't know much about IP tables, so I'm pretty much on my own to get this working. 
 
I...]]></description>
			<content:encoded><![CDATA[<div>I'm running VirtualBox for a class lab, and VirtualBox on Ubuntu appears to be missing the &quot;Bridge Interface&quot; feature for a network adapter - so the instructions we were given won't work for me, and the TA's don't know much about IP tables, so I'm pretty much on my own to get this working.<br />
<br />
I need my virtual server to be accessible from remote servers. My host machine has a publically routable address and can access the virtual machine through the local (and static) address 192.168.100.254, and so I figured I could just forward a port from my host machine to the virtual machine. My host can access the virtual machine through IP address 192.168.100.254, and I want to forward any tcp traffic on port 5345 (chosen at random) to my virtual machine. So I'm trying the following iptables commands on my host. I modified commands explained at <a href="http://www.debian-administration.org/articles/73" target="_blank">Port forwarding for iptables (DMZ)</a>, changing just the ports and the address.<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">iptables -A PREROUTING -t nat -i eth1 -p tcp --dport 5345 -j DNAT --to 192.168.100.254:80<br />
<br />
iptables -A INPUT -p tcp -m state --state NEW --dport 5345 -i eth1 -j ACCEPT</code><hr />
</div>The commands appear to execute successfully, but localhost:5345 and a similar request from a remote machine recieve no response. I haven't done anything else to the default iptables in Ubuntu, and the policy for FORWARD, INPUT and OUTPUT are all accept.<br />
<br />
<br />
Can anyone see anything wrong with the commands above (from my limited understanding of iptables - I dont see a problem), or am I going at this the completely wrong way?<br />
<br />
edit:<br />
<br />
I have set /proc/sys/net/ipv4/ip_forward to 1 (despite previous edits with problems I was having)</div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/networking-device-communication/">Networking/Device Communication</category>
			<dc:creator>sean</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/networking-device-communication/121135-using-ip-tables-forward-port-virtual-machine.html</guid>
		</item>
		<item>
			<title>winsock multithreaded server</title>
			<link>http://cboard.cprogramming.com/networking-device-communication/121121-winsock-multithreaded-server.html</link>
			<pubDate>Fri, 30 Oct 2009 10:32:16 GMT</pubDate>
			<description>Hii!! 
this is urgent , any help would be greatly appreciated!! 
i have a multithreaded server and many clients connect to it .The server client intercat in a derilaized manner i.e clienr sends something and based on what client sends the server responds appropraitely..So the thing is i have 2...</description>
			<content:encoded><![CDATA[<div>Hii!!<br />
this is urgent , any help would be greatly appreciated!!<br />
i have a multithreaded server and many clients connect to it .The server client intercat in a derilaized manner i.e clienr sends something and based on what client sends the server responds appropraitely..So the thing is i have 2 clients and both do the same intercation with the server.While the first client works fine ,the second one fails to recv data and send data at diiferent points in different runs..Dont know what is the problem... plz help!!!</div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/networking-device-communication/">Networking/Device Communication</category>
			<dc:creator>hardy1989</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/networking-device-communication/121121-winsock-multithreaded-server.html</guid>
		</item>
		<item>
			<title><![CDATA[my pc and laptop can't see my router]]></title>
			<link>http://cboard.cprogramming.com/networking-device-communication/121088-my-pc-laptop-cant-see-my-router.html</link>
			<pubDate>Thu, 29 Oct 2009 02:59:47 GMT</pubDate>
			<description>recently I did some home networking stuff after I bought a new laptop to connect my modem/router to another cisco router with wifi capability.Take note that my modem/router has no wifi and only 1 ethernet port. 
  After some googling and trial and errors,I finally connect my pc and laptop to the...</description>
			<content:encoded><![CDATA[<div>recently I did some home networking stuff after I bought a new laptop to connect my modem/router to another cisco router with wifi capability.Take note that my modem/router has no wifi and only 1 ethernet port.<br />
  After some googling and trial and errors,I finally connect my pc and laptop to the internet via my cisco router.For my cisco router,I configured so it's different subnet and also routing mode to &quot;router&quot; instead of &quot;gateway&quot;.However I'm puzzled as I can't detect my router via command &quot;route print&quot; or even see my cicso router lan ip in wireshark traces.<br />
<br />
    pc and laptop -----&gt; cicso router -------&gt; modem/router<br />
<br />
it seem my cisco router is in invisible mode but my modem/router is visible from my pc and laptop,I can't see my cisco router ip in my wireshark traces or &quot;route print&quot; command but my modem/router is visible.<br />
<br />
So is this normal ? my pc/laptop can connect to internet via my cisco router but my pc/laptop act as if my cisco router is invisible.<br />
<br />
cicso router<br />
=============<br />
1.Routing mode to &quot;router&quot;.(the others is gateway)<br />
2.different subnet<br />
3.disable dhcp<br />
<br />
modem/router<br />
=============<br />
1.lan ip to 192.168.0.1 (default gateway)<br />
2.same subnet as my pc/laptop<br />
3.enable dhcp</div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/networking-device-communication/">Networking/Device Communication</category>
			<dc:creator>kypronite</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/networking-device-communication/121088-my-pc-laptop-cant-see-my-router.html</guid>
		</item>
		<item>
			<title>send/receive udp from specific NIC</title>
			<link>http://cboard.cprogramming.com/networking-device-communication/121039-send-receive-udp-specific-nic.html</link>
			<pubDate>Tue, 27 Oct 2009 19:56:08 GMT</pubDate>
			<description>well the title sort of says it all.  I have a computer with multuple ethernet ports, I want to explicitly use one of those ethernet ports.  I know I could configure routing at the OS level to ensure specific port numbers go to a NIC, but is there a way I can control which NIC I use from within a...</description>
			<content:encoded><![CDATA[<div>well the title sort of says it all.  I have a computer with multuple ethernet ports, I want to explicitly use one of those ethernet ports.  I know I could configure routing at the OS level to ensure specific port numbers go to a NIC, but is there a way I can control which NIC I use from within a C++ program without modifying the OS?<br />
<br />
FYI I'll be running in a linux enviroment.<br />
<br />
Thanks.</div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/networking-device-communication/">Networking/Device Communication</category>
			<dc:creator>dsollen</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/networking-device-communication/121039-send-receive-udp-specific-nic.html</guid>
		</item>
		<item>
			<title>ftp connection error</title>
			<link>http://cboard.cprogramming.com/networking-device-communication/121023-ftp-connection-error.html</link>
			<pubDate>Tue, 27 Oct 2009 06:38:26 GMT</pubDate>
			<description><![CDATA[Code: 
--------- 
#include <windows.h> 
#include <stdio.h> 
  
WSADATA ws; 
int d; 
char aa[1000];  
char usr[100];]]></description>
			<content:encoded><![CDATA[<div><div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">#include &lt;windows.h&gt;<br />
#include &lt;stdio.h&gt;<br />
&nbsp;<br />
WSADATA ws;<br />
int d;<br />
char aa[1000]; <br />
char usr[100];<br />
char paswd[100];<br />
struct sockaddr_in a;<br />
SOCKET s;<br />
int ii;<br />
struct hostent *host;<br />
&nbsp;<br />
&nbsp;<br />
void abc(char *p)<br />
{<br />
&nbsp; &nbsp; &nbsp; &nbsp; FILE *fp = fopen(&quot;b.txt&quot;,&quot;a+&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; fprintf(fp,&quot;%s\n&quot;,p);<br />
&nbsp; &nbsp; &nbsp; &nbsp; fclose(fp);<br />
}<br />
&nbsp;<br />
_stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l)<br />
{<br />
&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d = WSAStartup(0x101,&amp;ws);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sprintf(aa,&quot; WSASTARTUP = %d&quot;,d);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; abc(aa);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s = socket(AF_INET,SOCK_STREAM,0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sprintf(aa,&quot; SOCKET = %d&quot;,s);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; abc(aa);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; host=gethostbyname(&quot;smartfile.com&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.sin_family = AF_INET;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.sin_port = htons(21);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.sin_addr.s_addr = *((unsigned long*)host-&gt;h_addr); <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d = connect(s, (struct sockaddr *)&amp;a, sizeof( a));<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; strcat(usr,&quot;USER xyzab\r\n&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; send(s,usr,sizeof(usr),0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ii = 1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ii = recv(s,aa,1000,0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; abc(aa);<br />
strcat(paswd,&quot;PASS abcdeg\r\n&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; send(s,paswd,sizeof(paswd),0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ii = 1;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ii = recv(s,aa,1000,0);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; abc(aa);<br />
}</code><hr />
</div>I need to upload a file using ftp connection so i wrote this code output i get is<br />
: WSASTARTUP = 0<br />
 SOCKET = 1940<br />
220 208.88.252.31 FTP server ready<br />
<br />
331 Password required for illusionist<br />
<br />
<br />
500 Invalid command: try being more creative<br />
<br />
rd required for illusionist<br />
<br />
<br />
I can't figure out why password command give error <br />
<br />
<br />
plz help.....</div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/networking-device-communication/">Networking/Device Communication</category>
			<dc:creator>illusionist</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/networking-device-communication/121023-ftp-connection-error.html</guid>
		</item>
		<item>
			<title>error 10057</title>
			<link>http://cboard.cprogramming.com/networking-device-communication/120881-error-10057-a.html</link>
			<pubDate>Thu, 22 Oct 2009 13:08:55 GMT</pubDate>
			<description>WSAGetLastError() returns 10057 ,meaning socket error, on the recv() function though i am connected. 
 
And the recv() function isnt blocking it loops around. 
 
Server and client in the same code. 
 
Thanks for any suggestions. 
 
 
Code:</description>
			<content:encoded><![CDATA[<div>WSAGetLastError() returns 10057 ,meaning socket error, on the recv() function though i am connected.<br />
<br />
And the recv() function isnt blocking it loops around.<br />
<br />
Server and client in the same code.<br />
<br />
Thanks for any suggestions.<br />
<br />
<div style="margin:20px; margin-top:5px">
	<div class="smallfont" style="margin-bottom:2px">Code:</div>
	<hr /><code style="margin:0px" dir="ltr" style="text-align:left">#include &lt;windows.h&gt;<br />
#include &lt;WinSock2.h&gt;<br />
#include &lt;iostream&gt;<br />
<br />
using namespace std;<br />
<br />
const int STRLEN = 256; char message[STRLEN] = {0};<br />
unsigned int port = 666;<br />
char recMessage[STRLEN] = {0};<br />
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);<br />
<br />
class Socket<br />
{<br />
&nbsp; &nbsp; protected:<br />
&nbsp; &nbsp; &nbsp; &nbsp; WSADATA&nbsp; &nbsp;  wsaData;<br />
&nbsp; &nbsp; &nbsp; &nbsp; SOCKET&nbsp; &nbsp; &nbsp; mySocket;<br />
&nbsp; &nbsp; &nbsp; &nbsp; SOCKET&nbsp; &nbsp; &nbsp; myBackup;<br />
&nbsp; &nbsp; &nbsp; &nbsp; SOCKET&nbsp; &nbsp; &nbsp; acceptSocket;<br />
&nbsp; &nbsp; &nbsp; &nbsp; sockaddr_in sockad;<br />
&nbsp; &nbsp; public:<br />
&nbsp; &nbsp; &nbsp; &nbsp; Socket();<br />
&nbsp; &nbsp; &nbsp; &nbsp; ~Socket();<br />
&nbsp; &nbsp; &nbsp; &nbsp; bool SendData( char* );<br />
&nbsp; &nbsp; &nbsp; &nbsp; bool RecvData( char*, int );<br />
&nbsp; &nbsp; &nbsp; &nbsp; void CloseConnection();<br />
&nbsp; &nbsp; &nbsp; &nbsp; void GetAndSendMessage();<br />
};<br />
<br />
class ClientSocket : public Socket&nbsp; //Inheritance<br />
{<br />
&nbsp; &nbsp; public:<br />
&nbsp; &nbsp; &nbsp; &nbsp; void ConnectToServer( const char *ipAddress, int port );<br />
}; ClientSocket sockClient;<br />
<br />
void ClientSocket::ConnectToServer( const char *ipAddress, int port )<br />
{<br />
&nbsp; &nbsp; sockad.sin_family = AF_INET;<br />
&nbsp; &nbsp; sockad.sin_addr.s_addr = inet_addr( ipAddress );<br />
&nbsp; &nbsp; sockad.sin_port = htons( port );<br />
<br />
&nbsp; &nbsp; if ( connect( mySocket, (SOCKADDR*) &amp;sockad, sizeof( sockad ) ) == SOCKET_ERROR )<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; cerr &lt;&lt; &quot;ClientSocket: Failed to connect\n&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; system(&quot;pause&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; WSACleanup();<br />
&nbsp; &nbsp; &nbsp; &nbsp; exit(13);<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; cout &lt;&lt; &quot;\nCONNECTED!\n\n&quot;;<br />
}<br />
<br />
void Socket::GetAndSendMessage()&nbsp;  //Member functions<br />
{<br />
&nbsp; &nbsp; cin.ignore();<br />
&nbsp; &nbsp; message[0] = '\0';<br />
<br />
&nbsp; &nbsp; cout &lt;&lt; &quot;You&nbsp; &nbsp; &gt; &quot;;<br />
&nbsp; &nbsp; cin.get( message, STRLEN );<br />
&nbsp; &nbsp; SendData( message );<br />
}<br />
<br />
bool Socket::SendData( char *buffer )<br />
{<br />
&nbsp; &nbsp;  send( mySocket, buffer, strlen( buffer ), 0 );<br />
&nbsp; &nbsp;  return true;<br />
}<br />
<br />
bool Socket::RecvData( char *buffer, int size )<br />
{<br />
&nbsp; &nbsp;  int i = recv( mySocket, buffer, size, 0 );<br />
<br />
&nbsp; &nbsp;  cout&lt;&lt;WSAGetLastError()&lt;&lt;&quot;\r\n&quot;;<br />
&nbsp; &nbsp;  cout &lt;&lt;i&lt;&lt; &quot;\n&quot;;<br />
<br />
&nbsp; &nbsp;  buffer[i] = '\0';<br />
&nbsp; &nbsp;  return true;<br />
}<br />
<br />
Socket::Socket()<br />
{<br />
&nbsp; &nbsp; if( WSAStartup( MAKEWORD(2, 2), &amp;wsaData ) != NO_ERROR )<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; cerr &lt;&lt; &quot;Socket Initialization: Error with WSAStartup\n&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; system(&quot;pause&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; WSACleanup();<br />
&nbsp; &nbsp; &nbsp; &nbsp; exit(10);<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; //Create a socket<br />
&nbsp; &nbsp; mySocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );<br />
<br />
&nbsp; &nbsp; if ( mySocket == INVALID_SOCKET )<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; cerr &lt;&lt; &quot;Socket Initialization: Error creating socket&quot; &lt;&lt; endl;<br />
&nbsp; &nbsp; &nbsp; &nbsp; system(&quot;pause&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; WSACleanup();<br />
&nbsp; &nbsp; &nbsp; &nbsp; exit(11);<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; myBackup = mySocket;<br />
}<br />
<br />
Socket::~Socket()<br />
{<br />
&nbsp; &nbsp; WSACleanup();<br />
}<br />
/////////////////////////////////////////////////////////////////////////<br />
class ServerSocket : public Socket&nbsp; //Inheritance<br />
{<br />
&nbsp; &nbsp; public:<br />
&nbsp; &nbsp; &nbsp; &nbsp; void Bind( int port );<br />
&nbsp; &nbsp; &nbsp; &nbsp; void Listen();<br />
&nbsp; &nbsp; &nbsp; &nbsp; void StartHosting( int port );<br />
};&nbsp; &nbsp; ServerSocket sockServer;<br />
<br />
void ServerSocket::StartHosting( int port )<br />
{<br />
&nbsp; &nbsp;  Bind( port );<br />
&nbsp; &nbsp;  Listen();<br />
}<br />
<br />
void ServerSocket::Bind( int port )<br />
{<br />
&nbsp; &nbsp;  sockad.sin_family = AF_INET;<br />
&nbsp; &nbsp;  sockad.sin_addr.s_addr = inet_addr( &quot;0.0.0.0&quot; );<br />
&nbsp; &nbsp;  sockad.sin_port = htons( port );<br />
<br />
&nbsp; &nbsp;  if ( bind ( mySocket, (SOCKADDR*) &amp;sockad, sizeof( sockad) ) == SOCKET_ERROR )<br />
&nbsp; &nbsp;  {<br />
&nbsp; &nbsp; &nbsp; &nbsp;  cerr &lt;&lt; &quot;ServerSocket: Failed to connect\n&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp;  system(&quot;pause&quot;); WSACleanup(); exit(14);<br />
&nbsp; &nbsp;  }<br />
}<br />
<br />
void ServerSocket::Listen()<br />
{<br />
&nbsp; &nbsp;  if ( listen ( mySocket, 1 ) == SOCKET_ERROR )<br />
&nbsp; &nbsp;  {<br />
&nbsp; &nbsp; &nbsp; &nbsp;  cerr &lt;&lt; &quot;ServerSocket: Error listening on socket\n&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp;  system(&quot;pause&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp;  WSACleanup();<br />
&nbsp; &nbsp; &nbsp; &nbsp;  exit(15);<br />
&nbsp; &nbsp;  }<br />
<br />
&nbsp; &nbsp;  acceptSocket = accept( myBackup, NULL, NULL );<br />
&nbsp; &nbsp;  while ( acceptSocket == SOCKET_ERROR )<br />
&nbsp; &nbsp;  {<br />
&nbsp; &nbsp; &nbsp; &nbsp;  acceptSocket = accept( myBackup, NULL, NULL );<br />
&nbsp; &nbsp;  }<br />
&nbsp; &nbsp;  mySocket = acceptSocket;<br />
&nbsp; &nbsp;  cout &lt;&lt; &quot;\nCONNECTED!\n\n&quot;;<br />
}<br />
<br />
////////////////////////////////////////////////////////////////////////////////<br />
///////////////////////////////////////////////////////////////////////////////<br />
//////////////////////////////////////////////////////////////////////////////<br />
<br />
int main()<br />
{<br />
&nbsp; &nbsp; string choice;<br />
&nbsp; &nbsp; string ipAddress;<br />
&nbsp; &nbsp; while(1){<br />
&nbsp; &nbsp; cout &lt;&lt; &quot;1) Client&quot; &lt;&lt; endl;<br />
&nbsp; &nbsp; cout &lt;&lt; &quot;2) Server&quot; &lt;&lt; endl;<br />
&nbsp; &nbsp; cin&nbsp; &gt;&gt; choice;<br />
<br />
&nbsp; &nbsp; /***************************************CLIENT***************************************/<br />
&nbsp; &nbsp; if ( choice == &quot;1&quot; )<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp;  cout &lt;&lt; &quot;ATTEMPTING TO CONNECT...&quot; &lt;&lt; endl;<br />
&nbsp; &nbsp; &nbsp; &nbsp;  sockClient.ConnectToServer( &quot;127.0.0.1&quot;, port );<br />
&nbsp; &nbsp; &nbsp; &nbsp; while (1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  sockClient.GetAndSendMessage();<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; sockClient.CloseConnection();<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; /****************************************SERVER***************************************/<br />
&nbsp; &nbsp; else if ( choice == &quot;2&quot; )<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp;  //(HANDLE)_beginthreadex(NULL, 0, LISTENandACCEPT , NULL, 0, &amp;Th2);<br />
&nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; &quot;\t--------------\n&quot; &lt;&lt; endl;<br />
&nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; &quot;\t****SERVER****\n&quot; &lt;&lt; endl;<br />
&nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; &quot;\t--------------\n&quot; &lt;&lt; endl;<br />
&nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; &quot;WAITING FOR CLIENT...&quot; &lt;&lt; endl;<br />
&nbsp; &nbsp; &nbsp; &nbsp; sockServer.StartHosting( port );<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; while(1)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sockClient.RecvData( recMessage, STRLEN );<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cout &lt;&lt; &quot;Friend &gt; &quot; &lt;&lt; recMessage &lt;&lt; endl; Sleep(1999);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; else&nbsp; cout &lt;&lt; &quot;\nType 1 or 2 Please!\n\n&quot;;<br />
&nbsp; &nbsp; }<br />
}</code><hr />
</div></div>

]]></content:encoded>
			<category domain="http://cboard.cprogramming.com/networking-device-communication/">Networking/Device Communication</category>
			<dc:creator>Ducky</dc:creator>
			<guid isPermaLink="true">http://cboard.cprogramming.com/networking-device-communication/120881-error-10057-a.html</guid>
		</item>
	</channel>
</rss>
