C/C++ :: Sending And Receiving Struct Over TCP Socket In Linux

Apr 4, 2012

I am trying to code a C program for sending a struct over TCP Socket in Linux! The code is as follows:

/*
** sravan_server.c - a stream socket (TCP) server Program 
*/
#include <stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<errno.h>
#include<string.h>

[Code] ....

View 4 Replies


ADVERTISEMENT

C++ :: Sending And Receiving Data?

Jul 23, 2014

If I have a text file named, stuff at a specified path in the c : drive, how do I send the contents of this file to another computer using the Internet?

View 5 Replies View Related

C++ :: UDP Socket Library On Linux

Jan 29, 2014

I'm attempting to write a little UDP socket library in c++ on linux so a user can just create a new instance of a UDPSocket class, specify destination ip and port, and just connect. Then the user should be able to call send() or receive() in any order they want.. and here I encounter a little problem..

Most of the tutorials for udp socket sending out there include a bind() call when you create your "server" that is supposed to receive data, but the code that send data does not need one. Because I also want my library to support unicast/broadcast/multicast, I have read that I need to set the socket option SO_REUSEADDR on my sockets (since multiple sockets will need to be connected to same destination IP/port for broadcast/multicast)

My question is.. do I need to create 2 socket handles per "UDPSocke in order to make this work? One for sending and one for receiving data? In my code when I try to work with only 1 socket, it is only able to receive stuff from itself on unicast.. Or should I just remove the SO_REUSEADDR when in unicast mode, then try to bind with both sockets, accept that the bind will only work on the 1st socket, and take it from there?

View 1 Replies View Related

C :: Sending Matrix Over UDP Socket

May 18, 2014

I want to apply program to send matrix from client and server ,and return back a processed matrix ..

How I can do it using UDP ,it was easy to use tcp for that!?

View 3 Replies View Related

C :: Sending Integer Via Socket

Dec 18, 2014

Verify my Method . I am not getting expected output ..

Code:

int Amount=500;
send(newSocket,Amount,4,0);
close(welcomeSocket);
recv(clientSocket,Amount,4,0);
// Amount= ntohl(Amount);
printf("Data received: %d",atoi(Amount[0]));

View 5 Replies View Related

C :: Linux Socket Multiple Connections But With Different Time Rate

Feb 6, 2015

i want to write a server and a client as below:

The server(and not the clients) will connect to the clients and just send a message. The idea is to be able to connect at each client a different time.

e.g
every 10mins connect at client 1
every 2mins connect at client 2
every 1hour connect at client 3
and so on...

So how to implement this ? Should i create a new child process for each connection and what about the timing ? A pseudo code also will work.

View 4 Replies View Related

C :: Address Family Not Supported By Protocol In Socket Programming In Linux

Oct 31, 2013

I am writing on C simple socket programs in Linux. I wrote client and server C programs. My client program is Code: #include<sys/socket.h>//for socket(), connect(), sendto() and recvform()

#include<sys/types.h>
#include<netinet/in.h>
#include<netdb.h>
#include<stdio.h>// for printf() and fprintf()

[Code]....

I am just testing whether can connect or not. I run server program first and client later. But when I run client, it showed that "Address family not supported by protocol".

View 3 Replies View Related

C/C++ :: TCPIP Socket Client Programming In Redhat Linux Using Eclipse CDT

Mar 16, 2014

This is my sample socket tcp ip program , problem here is when i give working ip address and port number, it is showing default ip address as 127.0.0.1 and it is Waiting on (1978=port number) i.e., "connection on %d...", SERVER_PORT.

void socket_server_demo(void){
int iserver_socket = -1;
int iclient_socket = -1;
unsigned char bTemp[1024];
unsigned int iTemp = 0;

[Code] ....

View 1 Replies View Related

C++ :: Struct Of Ints Via Socket?

Feb 7, 2014

I have some paper work to do about a game I should be able to play with my class mates. We should be able to send and recive a struct concerning about the 'moves' of the pieces at the game. This struct is made of 4 ints, simple as that.

I had a previous paper work to do where I'd have to send ints and that was ok, but now that I have to send a struct I'm failing to do so. This is What I've tried:

//SERVER
struct message{
int code;
int piece;
int x;
int y;
}send;
bytes_sent=write(new_socket,&send,sizeof(message));
cout<<bytes_sent;

So far so good, I see 16 as bytes_sent's value.

On the other hand:

//CLIENT
struct message{
int code;
int piece;
int x;
int y;
}recive;
bytes_recvd=read(my_socket,&recive,sizeof(message));
cout<<bytes_recvd;

I always see 0 as the bytes_recvd's value.

View 3 Replies View Related

C/C++ :: Receiving Information From A File?

Nov 13, 2014

I want to receive an information from a file. For instance, you created a file name "sample.txt" via fstream and stored a bunch of people's name, address, phone number in that "sample.txt".

Now, I want to see what's stored in this file. Suppose, I wanted some particular guys address, phone number by just typing is his/her name.

How to relate the name with address and phone number of particular people? I just started the file creating so I wanted to know about it.

#include<iostream>
#include<conio.h>
#include<fstream>
#include<string>
using namespace std;
int main() {
ofstream outputData;

[code].....

View 12 Replies View Related

C :: Client Not Receiving Time From Server

Sep 2, 2013

I'm building a client server which is communicating.I am trying to use the function recvfrom, but have several bugs, so I might have the recvfrom function in the wrong part of my code.

Code:

int talk_with_server(int fd) {
printf("Test.
");
char buf[LEN];
int n = read(fd, buf, LEN);

[Code]....

View 1 Replies View Related

C++ :: UDP Client Stop Receiving Packets

Jul 22, 2012

I have a simple UDP client that should be able to send and receive packets. It does its job, however if there are no packets received for a while it stops listening for any new packets and I'm not sure what's causing it.

This is my code:

#define WIN32_LEAN_AND_MEAN
#include "Client.h"
#include <winsock2.h>
#include <ws2tcpip.h>
#include <vector>
#include <sstream>
#pragma comment(lib, "Ws2_32.lib")

[Code] ....

View 1 Replies View Related

C :: Program Works Primarily By Receiving User Input

Jun 24, 2013

My program works primarily by receiving user input however; using 'char' and 'fgets' i have to stipulate how many characters i want assigned, and this isn't practical for what I am after. Example below.

Code:

char example[50];
printf("What colour is the sky?
");
fgets(example, 50, stdin); Is it possible that the assigned number (in this case '50') is determined strictly by the user input?

for example, user input is Blue then 50 is then 5?

View 9 Replies View Related

C :: How To Calculate Total Sum Of Delay Of Receiving Side Packet

Dec 17, 2014

I want to calculate the total some of delay pf receiving Side Packet . Code is as Follow ..

What is weird that even if i invoke a sleep of 2 sec ,than its show delay always zero. Delay will be in microsec ..Is there any problem with logic or anything else..

Code:

do
{#pragma omp parallel private(nthreads, tid) {
/* Obtain thread number */
tid = omp_get_thread_num();
if (tid == 0) {
nthreads = omp_get_num_threads();

[Code]...

View 2 Replies View Related

C++ :: Build Array Of A Size After Receiving User Input

Sep 25, 2013

I'm trying to build an array of a certain size, after receiving user input. The method I'm trying is

int var = 3;
int* ar = new int[var];

When doing tests I did this (and it worked) and red flags popped off in my head.

int var = 3;
int* ar = new int[var];
ar[0] = 0;
ar[1] = 1;
ar[2] = 2;
ar[3] = 3;
ar[4] = 4;
cout << ar[0] << ar[1] << ar[2] << ar[3] << ar[4] << endl;

This method is considered safe, and possibly tell me why I'm not getting stack errors when trying to overload the array?

View 9 Replies View Related

C Sharp :: Receiving Data Using Bluetooth Dongle (BLED 112)

May 30, 2013

I am doing a project where i need to develop a C# windows application. I need to receive data in my laptop (windows 7) using BLED 112 Dongle from NRF 8001 which is Bluetooth Low Power. Actually NRF 8001 is connected to a sensor and it is streaming the sensor's data. I need to receive those data using Dongle and save those data.

I tried doing this by using the library provided by 32feet.net but using this i could only discover the device but wasn't able to connect my Dongle to NRF 8001. So i couldn't proceed further and i am stuck since couple of weeks already ....

I already tried searching in the internet but didn't find much info however i recently i got a API for my Dongle in this link

[URL] .....

View 4 Replies View Related

Visual C++ :: Receiving Windows Message In Console Application?

Oct 11, 2013

I'm trying to write a program that passes Windows messages back and forth from another program that controls a laboratory instrument. I was able to write a program that successfully passes instructions, as evidenced by the instrument doing what I tell it. However, I am having trouble getting a return status from the instrument. The manual instructs the following:

// demo code, etc.
// send message to the instrument operating software here...
SendMessage(hwnd, WM_COPYDATA, tag, (LPARAM) &cd)

Either a completion message or return data is returned. Remote commands ReturnStatus, ReturnTiming, and ReturnData return data. In either case, data is received through an asynchronous windows message inside Win32 COPYDATASTRUCT type data packet.For example, a typical OnCopyData window callback is shown below, where the string data retrieved is finally stored into a Microsoft CString object. Note the use of variable replyTag, discussed above, which is used to isolate the correct windows message returned.

BOOL CUserDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* cd) {
….
if (cd->dwData == replyTag) {
/* String pointing to status */
CString retStatus = (char*) cd->lpData;
}
….
}

I can't tell if my problem is in generating the replyTag, getting the HWND to my own console window, or the actual receiving part of the code.

When setting the replyTag, the manual instructs: UINT replyTag = RegisterWindowMessage(“SOFTMaxProReplyMsg”);. However, I have to put an "L" in front of the string or I get a data type error (can't convert const char* to LPCWSTR).

When setting a HWND for myself, the manual instructs: HWND MyWnd = GetSafeHwnd().

That produces an error because GetSafeHwnd is a function of the Cwnd class, and I don't have a Cwnd. I have replaced it with HWND MyWnd = GetConsoleWindow();

When listening for the reply message, the manual instructs what I quoted above. However, I again don't have a Cwnd. I therefore simply used

if (cd.dwData == replyTag) {
CString retStatus = (char*) cd.lpData;
}

The above if statement always evaluates false, and the cd.lpdata contains the message that I had sent out instead of a reply message. How to get a reply using my console application. Here is the full code of my function:

Code:
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<string>
#include<afxwin.h>
using namespace std;
void SendCommand(string command) {
// Get tags to identify the receiving and sending messages

[code]....

View 3 Replies View Related

Visual C++ :: MFC- Receiving Button Click Message Failed

Oct 2, 2014

I've created a new dialog in my MFC dialog based application. the new dialog contains 5 control buttons. The following happens and I don't understand why?

1. click on buttonX. (result ok, OnBnClicked message is sent)
2. click on on any place of the application, but not on the dialog.(removing focus from dialog)
3. click again on buttonX (FAILED, OnBnClicked message is NOT sent). but if instead I click on any other button in the dialog (result ok, OnBnClicked message is sent).

And when I do:

1. ...
2. ...
3. click on the dialog area just to set focus on the dialog again
4. click again on buttonX. (result ok, OnBnClicked message is sent)
**I need to do step 3 only if I want to click again on the buttonX! why?? I think it related to SetFocus() but I m not sure how.

I've tried different style like, tool windows, overlapped, popup. it happens in all the cases.

Code:
class CToolsDlg : public CBDialog {
DECLARE_DYNAMIC(CToolsDlg)
public:
CToolsDlg(CWnd* pParent = NULL); // standard constructor
virtual ~CToolsDlg();
CToolTipCtrl m_ToolsTips;

[Code] .....

View 6 Replies View Related

C/C++ :: Sizeof (struct) Returns 6 More Bytes Than Actual Struct Size?

Sep 14, 2014

#include <stdio.h>
#define MAX_USERS 20
struct {
char ID[10];
char Name[40];
int Pos;

[Code] .....

I was attempting something weired with address to move data around when I discovered that the size of the array is not what I expected. I am passing this structure as &Users to a function that declares it as a void *, then I can deal with chunks of data (memmove) and not have to worry about index or things like that. However...sizeof is returning something I do not understand.

View 9 Replies View Related

C :: Debugging A Code On Linux OS

Apr 11, 2013

I have a code that I'd like to debugg it.

Question
1 - What is the correct command line to use the debugger ?
2 - Do I need to install additional software for the debugger ?

if yes what it's name?

I use ububtu 12.4compiling command: gcc abc.c -lpthread -o abc

View 3 Replies View Related

C :: Creating Shell In Linux

Feb 22, 2015

This is what so far i did

Code:
#include <stdio.h>#include <string.h>
#include <ctype.h>
#include <bsd/string.h>

int
main(void)

[Code] ....

How to do this Using the fork(), execvp() and waitpid() system calls, launches the requested program and waits until the program has finished.

View 3 Replies View Related

C :: Implementing GUI On Linux Platform

Jul 6, 2014

I am an experience C programmer but never implement GUI.

I need to make a demo implementation that will be run on Linux and will implement GUI.

I searched the WEB and found lot of information, among is implementing the GUI in HTML and run the API through web browser.

How can I make such implementation in C?

View 2 Replies View Related

C :: Compiling 2 Files In Linux Gcc

Sep 22, 2014

I want to use two separate files in 1 program, but cannot get it to work. I don't know if it's my files or the compiling thats wrong. I have never used 2 files in my programs so far. Only used #include <stdio.h>.

Here are my files:
extern_static.c Code: extern int i;
int main(void)
{

[Code]....

View 10 Replies View Related

C :: File Which Can Be Compiled In Linux Via GCC

Aug 16, 2013

I have a c file which can be compiled in Linux via GCC , but when I compile it in NetBeans via Cygwin or MinGW , it doesn't work and keeps throwing a segmentation fault.

View 14 Replies View Related

C++ :: Works On Solaris But Not On Linux?

Apr 24, 2013

I have this following piece of code:

int id = 5;
const char *ptrId;
ptrId = ( int_to_str(id) ).getPtr(); // Works in Solaris well

But the above code prints some junk values when I run the same on Linux machine. But the following works well on Linux:

String temp = int_to_str(id);
ptrId = temp.getPtr();

The prototype of getPtr() is:
const char* String::getPtr() const

View 2 Replies View Related

C/C++ :: Linux Console Get Key State

Jan 23, 2014

I want to create command line game in Linux but I don't know to get the key state. I heard of getch() but that stops the program.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved