{"action":"created","issue":{"url":"https://api.github.com/repos/jcw/ethercard/issues/290","repository_url":"https://api.github.com/repos/jcw/ethercard","labels_url":"https://api.github.com/repos/jcw/ethercard/issues/290/labels{/name}","comments_url":"https://api.github.com/repos/jcw/ethercard/issues/290/comments","events_url":"https://api.github.com/repos/jcw/ethercard/issues/290/events","html_url":"https://github.com/jcw/ethercard/issues/290","id":273801714,"number":290,"title":"TCP Equivalent of udpListener?","user":{"login":"con247","id":1981010,"avatar_url":"https://avatars2.githubusercontent.com/u/1981010?v=4","gravatar_id":"","url":"https://api.github.com/users/con247","html_url":"https://github.com/con247","followers_url":"https://api.github.com/users/con247/followers","following_url":"https://api.github.com/users/con247/following{/other_user}","gists_url":"https://api.github.com/users/con247/gists{/gist_id}","starred_url":"https://api.github.com/users/con247/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/con247/subscriptions","organizations_url":"https://api.github.com/users/con247/orgs","repos_url":"https://api.github.com/users/con247/repos","events_url":"https://api.github.com/users/con247/events{/privacy}","received_events_url":"https://api.github.com/users/con247/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-11-14T13:58:51Z","updated_at":"2018-04-14T13:03:40Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nThe udpListener sample is exactly what I need for my project (just sending text via UDP then processing it in a function). Is there a sample or any instructions on how to do the same with TCP? I have tried the code below to print a TCP packet sent to port 80 with the modified code below, however it prints the contents to the serial monitor multiple times and sends back TCP responses each time. I am using https://packetsender.com/ to send a packet. How can I setup the code so that I can send a packet to a selectable TCP port and just print the contents like the udpListener?\r\n\r\nNote: I re-arranged the code below so that \"my\" code was at the top for easier visability. The setup routine, etc, are in the same order as the sample udpListener.ino. Thanks in advance for any direction.\r\n```c++\r\nvoid loop(){\r\n  //this must be called for ethercard functions to work.\r\n  checkEthernet();\r\n}\r\nvoid checkEthernet() {\r\n  int payloadPos = ether.packetLoop(ether.packetReceive());\r\n\r\n  if (payloadPos) {\r\n    Serial.print(\"Payload Pos: \");\r\n    Serial.println(payloadPos);\r\n    char * incomingData = (char *) Ethernet::buffer + payloadPos;\r\n     Serial.println(incomingData);\r\n\r\n  }\r\n}\r\n\r\n//callback that prints received packets to the serial port\r\nvoid udpSerialPrint(uint16_t dest_port, uint8_t src_ip[IP_LEN], uint16_t src_port, const char *data, uint16_t len){\r\n  IPAddress src(src_ip[0],src_ip[1],src_ip[2],src_ip[3]);\r\n  \r\n  Serial.print(\"dest_port: \");\r\n  Serial.println(dest_port);\r\n  Serial.print(\"src_port: \");\r\n  Serial.println(src_port);\r\n  \r\n  \r\n  Serial.print(\"src_port: \");\r\n  ether.printIp(src_ip);\r\n  Serial.println(\"data: \");\r\n  Serial.println(data);\r\n}\r\n\r\n// Demonstrates usage of the new udpServer feature.\r\n//You can register the same function to multiple ports, and multiple functions to the same port.\r\n//\r\n// 2013-4-7 Brian Lee <cybexsoft@hotmail.com>\r\n\r\n#include <EtherCard.h>\r\n#include <IPAddress.h>\r\n\r\n#define STATIC 0  // set to 1 to disable DHCP (adjust myip/gwip values below)\r\n\r\n#if STATIC\r\n// ethernet interface ip address\r\nstatic byte myip[] = { 192,168,0,200 };\r\n// gateway ip address\r\nstatic byte gwip[] = { 192,168,0,1 };\r\n#endif\r\n\r\n// ethernet mac address - must be unique on your network\r\nstatic byte mymac[] = { 0x70,0x69,0x69,0x2D,0x30,0x31 };\r\n\r\nbyte Ethernet::buffer[500]; // tcp/ip send and receive buffer\r\n\r\nvoid setup(){\r\n  Serial.begin(57600);\r\n  Serial.println(F(\"\\n[backSoon]\"));\r\n\r\n  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)\r\n    Serial.println(F(\"Failed to access Ethernet controller\"));\r\n#if STATIC\r\n  ether.staticSetup(myip, gwip);\r\n#else\r\n  if (!ether.dhcpSetup())\r\n    Serial.println(F(\"DHCP failed\"));\r\n#endif\r\n\r\n  ether.printIp(\"IP:  \", ether.myip);\r\n  ether.printIp(\"GW:  \", ether.gwip);\r\n  ether.printIp(\"DNS: \", ether.dnsip);\r\n\r\n  //register udpSerialPrint() to port 1337\r\n  ether.udpServerListenOnPort(&udpSerialPrint, 1337);\r\n\r\n  //register udpSerialPrint() to port 42.\r\n  ether.udpServerListenOnPort(&udpSerialPrint, 42);\r\n}\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/jcw/ethercard/issues/comments/381327761","html_url":"https://github.com/jcw/ethercard/issues/290#issuecomment-381327761","issue_url":"https://api.github.com/repos/jcw/ethercard/issues/290","id":381327761,"user":{"login":"con247","id":1981010,"avatar_url":"https://avatars2.githubusercontent.com/u/1981010?v=4","gravatar_id":"","url":"https://api.github.com/users/con247","html_url":"https://github.com/con247","followers_url":"https://api.github.com/users/con247/followers","following_url":"https://api.github.com/users/con247/following{/other_user}","gists_url":"https://api.github.com/users/con247/gists{/gist_id}","starred_url":"https://api.github.com/users/con247/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/con247/subscriptions","organizations_url":"https://api.github.com/users/con247/orgs","repos_url":"https://api.github.com/users/con247/repos","events_url":"https://api.github.com/users/con247/events{/privacy}","received_events_url":"https://api.github.com/users/con247/received_events","type":"User","site_admin":false},"created_at":"2018-04-14T13:03:40Z","updated_at":"2018-04-14T13:03:40Z","author_association":"NONE","body":"I was trying to use this as a PoC for something at work, but I left the company shortly after this posting, so I didn't pursue it any further. I hope you figure out what you need!"}}
{"actor":{"display_login":"con247"}}