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
ADVERTISEMENT
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
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
View Related
Dec 18, 2014
I am trying to test my client-server socket program wherein the client connects to the server,client sends a message, server receives it and echo back to the client.So far, in the program server receives the message from the client, prints it BUT when it tries to send the message back to the client it shows an error.
sendto(): Invalid argument.I am new to socket programming.
Code:
//Server
#include<stdio.h> //printf
#include<string.h> //memset
#include<stdlib.h> //exit(0)
#include<netinet/in.h>
#include<sys/socket.h>
#define BUFLEN 512 //Max length of buffer
#define PORT 10003 //The port on which to listen for incoming data
}
[code]....
View 3 Replies
View Related
Sep 16, 2014
why this code works only for file of smaller data. When I try to send for istance a image, the image arrive corrupted.
Client:
//read all file
byte[] vett = File.ReadAllBytes(s);
//read filename
[Code]....
View 11 Replies
View Related
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
May 22, 2013
I am trying to send a packet across a client/server communication. I am getting a seg fault (while running the program(It compiles fine)) when I try to read the neighbor file, You should be able to see this below the comment /***** Read neighbor file***/ :
Code:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
}
[code]....
View 2 Replies
View Related
Feb 19, 2013
I'm having a bit of trouble learning how to multithread a socket server. I have everything working perfectly fine, but it only accepts one client (I would like multiple clients). some sort of example (I have troubles understanding some things, unless its visual).
View 4 Replies
View Related
Dec 17, 2014
get some opinions on, or established methods on how your buffer size should be decided.
View 2 Replies
View Related
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
Jun 28, 2014
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace test {
[Code] ....
I don't know if this is a bug in Winsock or the .NET Framework but i need to fix this or workaround. Recently I was working on a networking class and this error is breaking everything.
If you add Thread.Sleep(1) after Send() call then "TCP Bug detected" doesnt get executed but its not a reliable fix.
View 7 Replies
View Related
Jun 25, 2012
I have written a socket witch send an image 256x256 and now i want to send many images and i don't know what loop to write to make the socket after have sent the first image to send another and not to write the same program many times for every image ......
this is the part that read the binary image
if( !(fp=fopen("Anemos.bmp","rb"))) {
printf("Unable to load bin file: %s...
","Anemos.bmp");
[Code] ....
View 2 Replies
View Related
Oct 25, 2013
I am trying to assign the integer value to unsigned char array. But it is not storing the integer values. It prints the ascii values. Here the code snippet
Code: uchar uc[100];
for(i=0;i<100;i++)
{
uc[i] = i;
}
The values which are stored in uc[] is ascii values.I need the integer values to be stored in uc[]. I tried to do it with sprintf. but the output is not as expected. if I print the uc[i] it should diplay the value as 0,1,2....99.
View 9 Replies
View Related
Nov 21, 2013
What's the problem with the following:
Code:
#define K 3;
int max(int a, int b) {
return a>b? a : b;
} int main() {
cout<<max(K, K+3);
return 0;
}
Why is it not allowed, and how is it different from:
Code:
int max(int a, int b) {
return a>b? a : b;
} int main() {
cout<<max(3, 3+3);
return 0;
}
View 3 Replies
View Related
Oct 30, 2013
I have a socket connection already set up, my thing is what would be the best way to send a packet through sockets? My teacher wants us to convert the packet to bits first before we send it. I think he wants something like this:
Code:
struct packet{
int header
int message
int flag
}clientpacket; m
My question is how do we covert this to bits, before sending it. One of my friends said we can create a char[] array the size of the struct as a buffer. will memcpy() change the struct to bits if I copy it to the buffer?
this is how is suppose to look in bits for the header field/column.
Field : header
Field size(bits): 8
data format: Unsigned int
value example: 1
Value in bits: 0000 0001
I am confused, I think I send a structure over the socket but I did not convert it to bits before I sent it .
View 13 Replies
View Related
Nov 1, 2013
I want to write a program(s) so that the client sits and waits for a scanf to receive an int, then send to server, server then receives the int, processes it, then goes back to sit and wait for new input. to start with, where do i start! server side, or client side? and also what order do i have to go in my program before the loop to set up the socket, and listen? and then what gets looped to keep the connection open and wait for new receive?
View 4 Replies
View Related
Jul 21, 2013
I have a project, to make a program that spams chat programs. I've been trying to figure out how to send a string to an open program such as notepad, or a chat window. I know how to simulate keystrokes but I have yet to figure out or find out any way of sending a string to a program. pseudo code:
int main() {
string a;
int howManyTimes;
cin >> a;
cin >> howManyTimes;
//user enters "pizza"
for(int i = 0; i < howManyTimes; i++) {
//now I want "pizza" to be sent to the program keystroke enter or whatever the correct syntax is sleep
} }
View 1 Replies
View Related
Mar 1, 2013
I am writing some code to send text to a third part software. Basically each sending looks like this:
p << "set terminal eps
";
p << "set output '07.eps'
";
p << "plot '-' using ($1 == 0 ? NaN : $1) with lines linecolor 2 title 'comparison ratio',
'-' using ($1 == 0 ? NaN : $1) with lines title 'comparison ratio'
";
p.send(TOex_ar).send(TOnew_ar);
p << "set terminal wxt 7
";
p << "plot '-' using ($1 == 0 ? NaN : $1) with lines linecolor 2 title 'comparison ratio',
'-' using ($1 == 0 ? NaN : $1) with lines title 'comparison ratio'
";
p.send(TOex_ar).send(TOnew_ar);
Each time I have to change the number "07" and "7";decide to add or not the following parts: "using ($1 == 0 ? NaN : $1)", "with lines", "linecolor 2";and write the title 'comparison ratio' and the name of data to send "TOex_ar" and "TOnew_ar".Since I have to do this kind of thing 50 times in my code, and it is in the form of text, I am wondering whether in C++ we can write a template or function to simplify the program, just to input the changing parts.
View 3 Replies
View Related
Apr 20, 2014
I wanted to make an program which is sending messages to log in and password, but instead of message it gives me "System.Windows.Forms.TextBox, Text: AND HERE MY TEXT I WANTED.
View 9 Replies
View Related
Jan 10, 2015
create BOT that adds friends on one of Chat websites.
Im using C#
On website there is a button that adds user to friends
<li class="friend"><a href="javascript:void(0)">Add Friend</a></li>
I captured packet that is sended to server then that button is clicked
POST (info hided)/amfgateway.php HTTP/1.1Host: (info hided)
Connection: keep-alive
Content-Length: 52
[Code].....
It apears that this is AMF(Action Message Format) type packet Content-Type: application/x-amf it is in binary and this complicates things a little because I cannot send it with regular httpwebreqeuest class(Or I think so)
I used Fiddler4 with AMF plugin to check what data was passed with that packet
It apears that these numbers under content / 0 are User-id that is needed to add user to friends
I did a research with little success finding any usefull examples. I just found that there is a library for FLEX/FLASH remoting called fluorinefx and this should do the job but when I opened documentation it seems little too complex for me.
View 2 Replies
View Related
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
Jan 4, 2014
I would like to make a program for final project, which can let me send any file to my computer at home, and i can access any files in my computer when i am not at home.sending and getting file will be with socket programming.
i would like to reach all folders in computer, not only the folder, where client program exist. how can i access other folders at remote computer by using my program?
View 4 Replies
View Related
May 18, 2014
I make a simple c++ http post request using socket and it is working fine. But how to get only the message of the response. Here is my receive code:
char buffer[1028];
recv(socket, buffer, sizeof(buffer), 0);
printf("%s", buffer);
Then here is the response that the http send back.
HTTP/1.1 200 OK
Data: Mon, 19 May 2014 12:46:36 GMT
Server: Apache/2.4.9 (Win32) OpenSSL/0.9.8y PHP/5.4.27
X-Powered-By: PHP/5.4.27
Coneten-Length: 28
Content-Type: text/html
All done! Do some stuff now. So what I want to try is get 3 things in this response and put them to string vector but how to do this. What I need is to parse the response and the 200 OK, 28 and All done! Do some stuff now. then put them to string vector.
expected result
response[0] = 200 OK;
response[1] = 28
response[2] = All done! Do some stuff now
View 2 Replies
View Related
Mar 7, 2014
I Was Try To Change PictureBox To The Memory Stream And Then I Read Memory Stream Bytes And I Send Over The Netwrok Here Is Code
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); // we save the image in side the Memory strem
byte[] pic_array = new byte[ms.Length];
ms.Position = 0;
ms.Read(pic_array, 0, pic_array.Length); //
[Code]...
but when i want get the Data o mean Bytes from Network tream How can i save in memory stream then dispaly in the picture box ? i try some thing but it is gave me error !
Socket handlerSocket = (Socket)alSockets[alSockets.Count - 1];
NetworkStream networkStream = new
NetworkStream(handlerSocket);
int thisRead = 0;
int blockSize = 1024;
[Code]...
View 2 Replies
View Related
Mar 24, 2014
As requested by an exercise I have to write a function which:
- takes as parameter 1 unsigned which represent a timout value, 1 string which represent an IP address and an array containing port's numbers
- sends an UDP packet (1024 byte with NULL content) to each pair <IP,port>
- waits for the first reply, if it receives a packet within the timeout (set by select() function), the function returns the port of the process who replied, else it returns -1
I think I can do anything of above, but I've not understood how to set and use the select() in this case.
This is my code as it is at the moment
#define BUFLEN 1024
int comUDP ( unsigned timeout, char* ip, int ports[] ) {
int s_ds_sock, c_ds_sock;
struct sockaddr_in server_socket, client_socket;
char msg[BUFLEN] = NULL; //message to send to the clients
fd_set fds;
[Code] .....
View 2 Replies
View Related
Jun 15, 2014
changing a 9 digit integer into a new 9 digit integer through simple mathematical operations. For example, I need to change 123456789 into the new digit 456123789. Sometimes I need to change a 9 digit integer into an 8 digit integer. An example is 789062456 into 62789456. I can ONLY use simple mathematical operations (addition, subtraction, multiplication, division and modulo).
View 4 Replies
View Related