w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Client A change source mac address to Client B when send packet, But Client B's module can not rx packet after server sent
Probably because your switch has seen client B's MAC address on the port to client A and has remembered that. It will therefore send the reply on the ethernet port to client A, not to client B's erhernet port. This seems to be a networking issue, not a programming issue. Therefore this question might be more appropriate on a different forum.

Categories : Linux

Raw socket python packet sniffer
If you showed all the code, you are running into an endless loop. Whenever a paket is coming in which has not a length greater then 54 bytes, you end up reading the same packet all the time. Additionally, socket.recv() returns a string/byte sequence; your approach of accessing the data is wrong. pkt[0] returns a string with length 1; pkt[0][x:y] will not return something useful. I am not familiar with using sockets, but with some changes I got output that might look similar to what you intended (there is something missing in processEth() I think...). [...] while len(pkt) > 0: print "Waiting.." pkt = sock.recv(2048) print "received" if(len(pkt)) > 54: ethHeader = pkt[0:14] ipHeader = pkt[14:34] tcpHeader = pkt[34:38] ethH = struct

Categories : Python

python packet sniffer using raw socket
You could use: ctypes which is part of the standard library, or Construct which is designed to support network protocols, bitarray which isn't, bitstring which isn't as well. Here is an example: from ctypes import c_int32, c_uint32, Structure, Union class _bits(Structure): _fields_ = [ ("odd", c_uint32, 1), ("half", c_uint32, 31), ] class Int(Union): _fields_ = [ ("bits", _bits), ("number", c_uint32), ] a = Int(number=12345) a.bits.odd, a.bits.half the result: >>> a = Int(number=12345) >>> a.bits.odd, a.bits.half (1L, 6172L)

Categories : Python

Python send UDP packet
Your code works as is for me. I'm verifying this by using netcat on Linux. Using netcat, I can do nc -ul 127.0.0.1 5005 which will listen for packets at: IP: 127.0.0.1 Port: 5005 Protocol: UDP That being said, here's the output that I see when I run your script, while having netcat running. [9:34am][wlynch@watermelon ~] nc -ul 127.0.0.1 5005 Hello, World!

Categories : Python

difference between the destination IP of a crafted packet and the destination ip argument of raw socket send()
The answer for BSD is a comment in the source code for rip_output():1 "If the user handed us a complete packet, use it. Otherwise, allocate an mbuf for a header and fill it in" [i.e., from the address provided to sendto()]. For other systems you're going to have to read some kernel source code. G.R. Wright & W.R. Stevens, TCP/IP Illustrated, vol II: The Implementation, pp.1057-1062.

Categories : Networking

How to send a broadcast packet with specific format using Python
From the docs, here is a function that sends a message out on a socket: def mysend(self, msg): totalsent = 0 while totalsent < MSGLEN: sent = self.sock.send(msg[totalsent:]) if sent == 0: raise RuntimeError("socket connection broken") totalsent = totalsent + sent The sending code here is usable for almost any messaging scheme - in Python you send strings So you just need to build the string by prefixng it with '0x01'

Categories : Python

How to send a message to a particular client with socket.io
You can refer to socket.io rooms. When you handshaked socket - you can join him to named room, for instance "user.#{userid}". After that, you can send private message to any client by convenient name, for instance: io.sockets.in('user.125').emit('new_message', {text: "Hello world"}) In operation above we send "new_message" to user "125". thanks.

Categories : Javascript

Send image using TCP Socket Client App in Windows Phone
You could certainly write all of this yourself but have you possibly considered using a library to help save time? If so then checkout networkcomms.net, in particular a tutorial on sending non-primitive objects, using an image in the example, here. Disclaimer: I'm a developer for this library.

Categories : C#

Socket Client send using connection accepted by Server
Seems correct to me, but after read you have to NUL ('') terminate your buffer if you are treating with strings: buf[bytes_read] = '';

Categories : C++

how do i get my tornado ioloop socket client to send back respose after receiving?
i had set my sockets to nonblock mode, but i did not catch an error when accepting from a nonblock state when there is no connection: here: def reader(self,fd,event): result = b"" if event == self.loop.READ: self.conn, self.addr = self.sock.accept() should be def reader(self,fd,event): result = b"" if event == self.loop.READ: try: self.conn, self.addr = self.sock.accept() # we get stuck here self.connl.append(self.conn) except Exception as e: pass

Categories : Python

Server/Client program in C: how to send correctly dimension of structure elements via socket?
So, you need to allocate memory to username before assigning any value to it. Try using malloc within your thread or even a simpler approach - replace your struct struct giocatori { char* username; int userthread; }; with struct giocatori { char username[20]; //some random value for array length int userthread; };

Categories : C

Python socket.send encoding
# -*- coding:utf-8 -*- text = u"text in you language" s.send(u"Bing translation: " + text.encode('utf8') + u" "); This must work. text must be spelled in utf-8 encoding.

Categories : Python

client to server, socket in python many to one relationship
When your server's socket receives a connect attempt from a client, s.accept() returns the a socket object and ip,port information. What you need to do is save this new socket object in a list and poll this list. while True: c, addr = s.accept() clients.append(c) pressed = 0 Or better yet, use a dictionary of the ip:port tuple, and iterate over clients.iteritems() while True: c,addr = s.accept() clients[addr] = c A naive implementation might be: import socket clients={} server = socket.socket() host = socket.gethostname() port = 12349 s.bind((host, port)) s.listen(5) while True: c, addr = server.accept() clients[addr] = c pressed = 0 for eachsocket, eachaddrtuple in clients.iteritems(): print 'receiving data from %s'%eachaddrtuple data = c.recv(1024

Categories : Python

How to create a multi-client socket in Python?
import socket servers = [] #add servers here class Clients: def __init__(self): self.socket = new socket() #change this to full socket init def connect(self, url): self.socket.connect(url) def send(self, data): self.socket.send(data) def close(self): self.socket.close() for url in servers: client = new Clients() client.connect(url) client.send('abcd') client.close() Something like that ? Also this is general code just as an idea or example, it will not work if try to run it. Threads will work better, since it will not go sequentially and wait for sockets to connect and send data etc...

Categories : Python

Python: .send function of socket programming
As the documentation for socket states: The return value is a pair (string, address) where string is a string representing the data received and address is the address of the socket sending the data. So your ('hello', None) is this pair and if you want to pick the message string from it to search it in your dict, you have to use msg[0].

Categories : Python

Python Web Service vs Socket programming Client/Server Design
You should be able to use socket programming for this. Setup a socket server at the PC and a client at MiniPC devices. The clients would wait for input (read from socket) from the PC and then send back the output that they would get back from hardware. In terms of design, I see two things. First, the socket server can run a select() to handle multiple clients. Second, you probably want to bump up the SO_SNDBUF socket option for MiniPC sockets and SO_RCVBUF for the server at PC to multiples of 10Kb. What is your argument for considering Web?

Categories : Python

Python Simple Sever and Client script (Socket programming)
while True: client_socket, address =server_socket.accept() print "Connection from ", address data = client_socket.recv(512) print "RECIEVED:" , data This should be: client_socket, address =server_socket.accept() print "Connection from ", address while True: data = client_socket.recv(512) print "RECIEVED:" , data server_socket.accept() will wait indefinitely until a new client is connected. Actually your loop is like : "accept a client and receive one time the data he sent".

Categories : Python

Transmitting/Sending big packet safely using TcpClient/Socket
As you are using TCP, the network protocol will ensure that packets are received in the same order as sent. Regarding thread safety it depends a bit on the actual class which you are using for sending. The declaration part is missing in your provided code fragment. Given by the name you seem to use Socket and this is thread-safe, so every send is actually atomic, if you use any flavor of Stream, then it is not thread-safe and you need some form of synchronization like a lock, which you are currently using anyway. If you are sending large packets, then it is important to split the receiving and processing part into two different threads. The TCP buffer is actually a lot smaller than one would think and unfortunately it is not covered inside the logs when it is full as the protocol will keep

Categories : C#

Enable UDP packet checksum in C INET Socket Code
Kudos to TCP/IP Illustrated referenced in the comment, but it is a bit aged. The packet capture tool Wireshark will happily show you the UDP checksum. You did not mention your specific platform, but these days it is safe to assume it might be Linux. Folklore (I have no reference) says it might depend on the network interface device driver, but in my experience the UDP checksum is always added on Linux, when you send packets via regular UDP sockets. Your code is a bit strange in the way that it tries to capture packets it sends itself. I adapted the code a bit and used netcat as the receiving server. I verified that UDP checksums are present and correct by running wireshark on the client side. Here is a link to the slightly modified code http://pastebin.com/X9cgH1S3 Caveat emptor, testi

Categories : C

Python Client/Server send big size files
TCP sockets are byte streams, not message streams. If you want to send a series of separate messages (like your separate files), you need to define a protocol, and then write a protocol handler. There is no way around that; just guessing at the timing or trying to take advantage of packet boundaries cannot possibly work. The blog post linked above shows one way to do it. But you can do it with string delimiters if you want. But you have to deal with two problems: The delimiter can appear anywhere in a read packet, not just at the end. The delimiter can be split on packet boundaries—you may get "2929" at the end of one read, and the other "29" at the start of the next. The usually way you do that is to accumulate a buffer, and search for the delimiter anywhere in the buffer. Somethin

Categories : Python

conn.sendall(os.system(... .sh)) not send for my client python
os.system return exit status of subprocess. If you want send the output of sensor1.sh: import subprocess ... conn = ... ... out = subprocess.check_output(['./sensor1.sh']) conn.sendall(out)

Categories : Python

How to receive web socket message from server in client side by html5 socket api
Its always good practice before connecting to websockets, to check if the browser your user is using supports them....like so.... //First check for firefox, and set it to regular websocket...since Mozilla API is differently named if (window.MozWebSocket) { window.WebSocket = window.MozWebSocket; } //Then continue with checking var connection = {}; function connect() { if(window.WebSocket != undefined) { if(connection.readyState === undefined || connection.readyState > 1) { connection = new WebSocket('ws://127.0.0.1:80'); } } }

Categories : PHP

Why do I received UDP socket answer randomly with Asynchronous UDP client socket?
That's how UDP works. UDP is a protocol that provides an unreliable, unordered data delivery between devices connected to an IP network. It is generally considered a "layer 4" protocol in the OSI stack. One popular use of UDP is for transport of time-sensitive information, such as Voice over IP. UDP is specified in RFC 768. http://www.techabulary.com/u/udp/ You either need to use TCP, or be prepared to handle the out-of-order (and possibly completely missing) responses. SCTP is another option for your transmission protocol.

Categories : C#

Java Socket server not recieving data from client socket
Your client doesn't close the socket. Your server reads the socket until EOS, which will never arrive as your client doesn't close the socket. NB don't handle client I/O in the accepting thread. Start a separate thread.

Categories : Java

Socket.io : what happen to the client(socket) after a user is disconnected? Can I/Should I remove it?
In the code above, it is setInterval that is causing the additional logging. You will need to store off the id returned from setInterval then clear it using clearInterval on a disconnect event. Something like: io.sockets.on("connection",function(socket){ var intervalId = setInterval(function(){ console.log("Server calling update collection with socket No.",socket.No); },3000); //When connection is close() socket.on("disconnect",function(){ console.log("A user disconnected"); clearInterval(intervalId); }); }) Other than that, no need to do anything else with the socket on the server side. It will get garbage collected at some point.

Categories : Node Js

Linux raw datalink layer socket only returns partial packet (96 bytes)
Solved it! What I failed to mention in my original post was that I was attaching a filter to the raw socket so it would only receive traffic on certain TCP/IP ports. This filter code was created with TCPDUMP, which apprently limits capture to 96 bytes by default. I had to add the -s0 option to my TCPDUMP command line to tell it to capture everything: tcpdump -dd -s0 "ip and tcp and dst port 60001". With that change, it now gives me the full packet. Thanks to this blog post for the clue. Hope this helps someone else in the future.

Categories : Linux

Are there relevant differences in sending many small packets or one large packet on socket.io?
I believe the following link does a good job explaining a packet's life-cycle: http://www.sdsusa.com/connections/ The obvious takeaway is that with one packet all of the states (connection, acknowledgement, establish, send etc etc) happen once, as opposed to sending multiple packets those states have to happen once per packet. More packets will most likely result in a longer send/receive time with more connections to be made and a larger chance of dropped packets and missed connections causing additional latency. Most likely it won't matter which approach you go with because the difference will probably be a few ms and unnoticeable. That being said if you are many packets from many clients then your server could be flooded while trying to process 30 or 40 packets a second. Additional

Categories : Javascript

Python's asyncore client send only last element from list inside a thread
Asyncore is an asynchronous framework, as such, you don't control when you write to the network. You have two options here: Use regular, synchronous sockets Append to the buffer instead of replacing it The second option is quite self-explanatory, so here's how you'd do it with regular sockets: import socket class TestClient(object): _buffer = "" def __init__(self, host, port): self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.connect((host, port)) def writable(self): return (len(self._buffer) > 0) def write(self): while self.writable(): sent = self.send(self._buffer) self.buffer = self._buffer[sent:] def link(self, name): return name.replace(' ', '%20') def sendArtist(s

Categories : Python

send one big packet of many small over TCP/UDP?
When you send a string, that might be sent in multiple TCP packets. If you send multiple strings, they might all be sent in one TCP packet. You are not exposed to the packets, TCP sockets are just a constant stream of data. Do not expect that every call to recv() is paired with a single call to send(), because that isn't true. You might send "abcd" and "efg", and might read in "a", "bcde", and "fg" from recv(). It is probably best to send data as soon as you get it, so that the networking stack has as much information about what you're sending, as soon as possible. It will decide exactly what to do. You can send as big a string as you like, and if necessary, it will be broken up to send over the wire. All automatically. Since in TCP you don't deal with packets, things like lost packets a

Categories : Python

A java Socket is a TCP socket. Do I send TCP header information to a website?
do I have to strip away the IP and TCP headers when sending the data through a Socket() in java? Or do I leave the TCP header intact? You don't have the TCP header to strip. You just send and receive data. I tried plain socket, but it was not connecting ... So then I tried using a blocking SocketChannel There's no difference for this purpose between Socket and SocketChannel. If you're using either of them you are only concerned with the data payload, not the IP or TCP headers. Also if don't mind answering another question for me. When I get the payload I try to search for "GET" in hex values (0x47,0x45,0x54) to find the HTTP header, but I never find one. Is this right? I check the IP address requested and its asking for google.com. One thing though is that the port is 443 wh

Categories : Android

How to make client socket wait for server socket
boolean scanning=true; while(scanning) { try { socketChannel.open(hostname, port); scanning=false; } catch(ConnectionException e) { System.out.println("Connect failed, waiting and trying again"); try { Thread.sleep(2000);//2 seconds } catch(InterruptedException ie){ ie.printStackTrace(); } } } This is the code for sonics comment

Categories : Java

Chat client - Socket and server socket concurrently
ServerSocket blocks and that's it. But if you only want peer-to-peer communication between two connected parties and nothing more then this behavior is not a problem. You just need two programs: server and client. Server block until it gets connection from client and client blocks until it gets connection. If you want to implement Java IO in single thread you should use Java Nio. There are lots of tutorials for that in internet. For example http://tutorials.jenkov.com/java-nio/server-socket-channel.html. Also it seems that you are not very familar with networking and sockets so it might be beneficial to use some layer instead of raw sockets. Maybe you should consider JeroMQ (https://github.com/zeromq/jeromq) for implementing communication between programs.

Categories : Java

I can't send UDP packet from Android to Arduino
have you set the following Permissions in your Manifest file? uses-permission android:name="android.permission.INTERNET" uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"

Categories : Android

Combine multiple variables to send as a udp packet
It depends on the requirements for your network. Do you care about endianness? If you do, you should use not just any serialisatioin, but a safe one in regards to endianness. Generally, each class/struct sendable through the network should have special methods or overloaded operators to stream them in and out. Ultimately you'll have to use macros/functions like hton/ntoh for streaming primitive types eg int, int64, float, double etc. Upd: also if your network endpoint applications run on different platforms/compilers, you may have different sizes of int, long, short etc. So when serialising, you'll have to convert your integers to some predefined types with sizes guaranteed to be the same on all supported platforms.

Categories : C++

When I use AsyncUdpSocket object to send IP packet, It is not always working
After one week fight, I found the problem is caused by the RunLoop. I am using GCDAsyncUDPStoket to replace AsynvUdpSocket, then the problem solved! GCDAsyncUdpSocket *gcdAsyncUdpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];

Categories : IOS

Send packet with sockets from kernel module
I found an alternative solution, using netpoll sockets. It is more easier than sockets, I used before and it works. The answer and proper code is here, on another StackOverflow question.

Categories : Sockets

Client Socket Connections Being Denied By Server on Windows Host For Small Number (16 < x < 24) of Simulataneous Client Connection Attempts
I would check how many connections are in the TIME_WAIT state of the TCP connection. I have seen this type of problem due to many connections being open/closed causing socket exhaustion due to the TIME_WAIT. To check it, run: netstat -a

Categories : Java

Can socket objects be shared with Python's multiprocessing? socket.close() does not seem to be working
The problem is that the socket is not closed in the parent process. Therefore it remains open, and causes the symptom you are observing. Immediately after forking off the child process to handle the connection, you should close the parent process' copy of the socket, like so: while True: print "accepting" c, _ = s.accept() p = Process(target=process, args=(c,)) p.start() print "started process" c.close()

Categories : Python

aSmack - Packet to XML using Packet Listener outputs nullable elements
After lot of research and looking Smack sources, I found out the solution. The steps are, add IQProvider, add a PacketListener for your packet, send the packet. Wait for the packet on your IQProvider, parse it, and get your response on your Listener. So the addIQProvider and addPacketListener were both right, the thing is, I need to do the complete parse of the XML on my ListIQProvider, it sounds simple but took me some time to figure that out. public class ListIQProvider implements IQProvider { public ListIQProvider() { } @Override public IQ parseIQ(XmlPullParser parser) throws Exception { Logger.d(String.format("Received iq packet, namespace[%s], name[%s]", parser.getNamespace(), parser.getName())); ListIQ iq = new ListIQ(); ListIQ.Set set = new Set(); boolean d

Categories : Android

Socket error - with simple socket programming using python
The problem with windows sockets is that they don't actually die when you close them unless you tell them to. Try adding the following code after you initialise the socket and see what happens. l_onoff = 1 l_linger = 0 s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', l_onoff, l_linger)) The documentation for Lingering can be found at MSDN. also change your shutdown to: s.shutdown(socket.SHUT_RDWR) This should close all connections immediately if windows behaves itself. Which will prevent the buffer error caused by too many sockets lingering.

Categories : Python



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.